How can I use the operator or prevent repetition. In other words, the regular expression:
(word1|word2|word3)+
will match word1word2 , and will also match word1word1 , which I don't want, because word1 is repeated. How can I avoid a repeat?
In conclusion, I will like the following items:
word1word2word3 word1 word2 word3word2
Please note that they all match because there is no repetition. And I will not like the following items:
word1word2word1 word2word2 word3word1word2word2
Edit
Thanks @Mark I know:
(?xi) (?: (?<A>word1|word2)(?! .* \k<A> ) # match for word1 or word2 but make sure that if you capture it it does not follow what it was just captured | (?<B>word3|word4)(?! .* \k<B> ) )+
because I am interested to see that something was dropping in group A or B.
Tono nam
source share