Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

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

by haukex (Archbishop)
on Sep 14, 2020 at 12:28 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11121726]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2024-04-25 19:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found