in reply to regex backreference
my @words = $txt =~ m/\b(\w{3})\b(?=.*\b\1\b)(?!.*\b\1\b.*\b\1\b)/g;
The (?!...) is a negative look-ahead assertion. If you leave that out, duplicates appear for words occurring more that twice. And (?=...) is the positive look-ahead assertion.
|
|---|