in reply to Re: RegEx ignoring intervening characters?
in thread RegEx ignoring intervening characters?
edge case? specs?
To illustrate; note the use of three (In some ways, more precise, I think but am inviting begging for other views, please?) distinct regexen, $stuff1, $stuff2, and $stuff3 and the last line of __DATA__ and the LAST line of output
use strict; use warnings; my $stuff1 = qr/[^A]|[^C-Z]*/; my $stuff2 = qr/[^A-B]|[^D-Z]*/; my $stuff3 = qr/[^A-C]|[^E-Z]*/; my $regex = qr{ A $stuff1 B $stuff2 C $stuff2 D }x; while (my $line = <DATA>) { chomp($line); if ($line =~ $regex) { print "Matched: \" $line \"\n"; } else { print "**Did NOT match \"$line\"\n"; } } __DATA__ ABhere is intervening textC D A B C, lots of text and numbers and equals and slashes DEFG ABhere IS intervening TEXTC D A BIG foo is B intervening text CD A Big Cat interjects itself into text before CD
OUTPUT:
Matched: " ABhere is intervening textC D "
Matched: " A B C, lots of text and numbers and equals and slashes DEFG "
**Did NOT match "ABhere IS intervening TEXTC D"
**Did NOT match "A BIG foo is B intervening text CD"
Matched: " A Big Cat interjects itself into text before CD "
In the last line of __DATA__ an uppercase "C" preceeds another uppercase "C" (penultimate character), yet the regex does not object (i.e., says there's a match).
Update: Someone upvoted this as I was updating it -- to fix mental and typographic glitches; the said updating may have removed what the ++er thought was meritorious. Sorry.
|
|---|