Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2020-11-26 01:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?