Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Basic Regular expression

by Laurent_R (Canon)
on Feb 09, 2017 at 18:10 UTC ( #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? | Other CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2022-12-01 18:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?