Problems? Is your data what you think it is? | |
PerlMonks |
Re^2: regex question/mysteryby davido (Cardinal) |
on Jan 17, 2006 at 18:58 UTC ( [id://523806]=note: print w/replies, xml ) | Need Help?? |
Your conclusion is wrong. Alternation has very low precedence, and binds loosely. In the following expression, alternation provides two alternatives, the complete expression on the left, or the complete expression on the right:
The string matched by that RE must contain either "fast break" or "breakfast" (or both, but it wouldn't matter). In either case, 'break' is captured, but $& tells the rest of the story. Witness the following code:
The alternation is constrained on each side only be the / (the beginning and end of the RE, not by (break). That being the case, there is no need to have introduced additional parenthesis in the OP's regex. In fact, you have now changed the outcome of his RE in another way; to get at the data he intended to capture, he now must look at $2 or $4. Dave
In Section
Seekers of Perl Wisdom
|
|