Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: RegEx + vs. {1,}

by Anique (Acolyte)
on Oct 10, 2012 at 12:26 UTC ( #998216=note: print w/ replies, xml ) Need Help??


in reply to RegEx + vs. {1,}

The problem is not with the (\w{2,}?), because it will happily match to ab in

$x =~ /((\w{2,}?).*\g2.*?)+/;

and

$x =~ /((\w{2,}?).*?\g2.*?)+?/;

You are asking the regex to give you a sequence which is repeated, and you can either get the longest match (greedy) or the shortest one (ungreedy)

The only solution for your problem that I can think of, is to capture all matches that this regex finds (list context), then counting how often each captured sequence occurs, and selecting the one that occurs most often.


Comment on Re: RegEx + vs. {1,}
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (17)
As of 2015-07-29 14:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (263 votes), past polls