Reputation: 21
I have the following words in a text field (called Criticality):
Confidentiality;Confidentiality
I want to be able to determine if this field contains duplicate (or reoccurring words)
if Criticality == Confidentiality;Confidentiality then Yes (meaning it has words re-occurring.
if Criticality == Confidentiality;Availability then No (meaning it does not have any word re-occuring).
I have tried using regex match with the following syntax:
$(RegexMatch(Criticality, /(\b\w+\b)(\s+\1)+/i))
but it does not work. Not sure if someone could guide me.
Upvotes: 2
Views: 189
Reputation:
This is the regex to determine if your field contains duplicate words
(?<![^;])(\w+)(?![^;])[\S\s]*(?<![^;])\1(?![^;])
https://regex101.com/r/iOkI9d/1
Upvotes: 0
Reputation: 780949
Your words are separated by ;
, but the regexp requires them to be separated by \s+
, which is whitespace.
If you want to allow any non-word characters to separate them, you can use \W+
.
You should also put \b
around the back-reference, so it only matches a whole word.
(\b\w+\b)(\W+\b\1\b)
Upvotes: 1