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".
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|