Brian Fraser wrote:
On Tue, Oct 18, 2011 at 12:32 AM, Chris Stinemetz
<chrisstinem...@gmail.com>wrote:
/17|18|19|20|21+:(\d+):(\d+)+\n+\n+CELL\s+(\d+)\s+(.+?),.+?HEH/
Spot the issue:
/
17 #Or
| 18 #Or
| 19 #Or
| 20 #Or
| 21+:(\d+):(\d+)+\n+\n+CELL\s+(\d+)\s+(.+?),.+?HEH
/x
For anything but 21, the regex is only two numbers! You need to enclose the
alternatives in () or (?:), depending on whenever you want to capture them
or not.
That aside, please be very mindful that \d and . are both code smells. The
former will match much, much more than just [0-9] -- grab the unichars[0]
program from Unicode::Tussle[1] if you want to see for yourself. Either use
the /a switch (or the more localized form (?a:), bot available in newer
Perls), or [0-9], or \p{PosixDigit}, or (your favorite way here. TIMTOWTDI
applies).
The dot is also problematic. You aren't using the /s switch, so it actually
matches [^\n].
Correct.
Is that what you want? Are you certain that no one is going
to come and, after reading Perl Best Practices, will try to helpfully but
wrongly add the /smx flags and screw up your regex?
It doesn't really matter because the regular expression is matched
against a "line" (via readline) and as such will only contain one
newline and that newline will be at the end of the "line" so it will
match the same with or without the /s option.
Also, as the regular expression does not contain either the ^ anchor or
the $ anchor it will match the same with or without the /m option.
John
--
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction. -- Albert Einstein
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/