The problem is that on the first match, the \w\w\w matches the first and, but the .*? matches " him him lad has him done ", and the \g1 then matches the second and. The regex engine then continues matching after this entire match, i.e. at john, so it only finds has has, and then it reaches the end of the string so there are no more matches. I assume the point of this exercise is to learn about zero-width lookarounds - read up on them at perlre and try the regex / (\w\w\w) (?= .*? \1 ) /gx.
In reply to Re: regex, find words that occur more than once.
by haukex
in thread regex, find words that occur more than once.
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |