Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Basic Regular expression

by Laurent_R (Canon)
on Feb 09, 2017 at 18:10 UTC ( [id://1181557]=note: print w/replies, xml ) Need Help??


in reply to Basic Regular expression

You've been given good answers already, but let me just add some details on the way the regex engine processes this string.
According to me, it should be "$1= This is Perl".
In fact, that's what is initially happening: the regex engine sees (.+) and grabs the whole string, i.e. "this is Perl". But then, it sees (e|r), so, in order for the whole regex to be successful, it has to backtrack and give back "l" and then "r", so that (e|r) can be successful. Note that this would happen even if you did not have capturing parentheses, so that the point is not so much that it is trying to populate $2, but that (e|r) has to match something for the whole regex to be successful.

Once it has matched the "r" with the second capture, the last part of the regex, (.*)$ can match the "l".

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2024-04-26 09:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found