Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re: regex, find words that occur more than once.

by haukex (Bishop)
on Sep 14, 2020 at 12:28 UTC ( #11121726=note: print w/replies, xml ) Need Help??

in reply to regex, find words that occur more than once.

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.

Replies are listed 'Best First'.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11121726]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2021-03-01 02:02 GMT
Find Nodes?
    Voting Booth?

    No recent polls found