in reply to Delimiters in Regexp::Common
... a bug with the module.
The behavior you're seeing is due to confusion between the // used to delimit the regex and a / used within the regex. IIRC, Regexp::Common mungs the regex operators | uses the tie-ed hash %RE to support things like -delim and -keep and so forth, and apparently the delimiter confusion is passed over silently as a result. "Properly" delimited regexes don't have this problem:
What I have for $Regexp::Common::VERSION and $Regexp::Common::delimited::VERSION are 2011121001 and 2010010201, respectively, so what I have installed is a bit old. Same results under both ActiveState 5.8.9 and Strawberry 5.14.4.1.c:\@Work\Perl\monks>perl -wMstrict -le "use Regexp::Common qw[ delimited ]; my $P1 = '../matrix-ops/matopmul.mk'; my $P2 = 'C:\matrix-ops\matopmul.mk'; print \"P1 has path\n\" if ($P1 =~ /$RE{delimited}{-delim => '\/'}/ ) +; print \"P2 has path\n\" if ($P2 =~ /$RE{delimited}{-delim => '\/'}/ ) +; " P1 has path c:\@Work\Perl\monks>perl -wMstrict -le "use Regexp::Common qw[ delimited ]; my $P1 = '../matrix-ops/matopmul.mk'; my $P2 = 'C:\matrix-ops\matopmul.mk'; print \"P1 has path\n\" if ($P1 =~ m{$RE{delimited}{-delim => '\/'}} +); print \"P2 has path\n\" if ($P2 =~ m{$RE{delimited}{-delim => '\/'}} +); " P1 has path P2 has path
I don't know if this behavior constitutes a bug in the module or not, but in regexes in general, if a character that's used to delimit the regex appears unescaped within the regex, that's a problem:
c:\@Work\Perl\monks>perl -wMstrict -le "print 'match' if '/' =~ ///; " syntax error at -e line 1, near "/;" Execution of -e aborted due to compilation errors. c:\@Work\Perl\monks>perl -wMstrict -le "print 'match' if '/' =~ /\//; " match
(And BTW: I'm not sure how the presence of a delimited sequence or subsequence signifies a "path"; there may be some semantic confusion here.)
Update 1: If you're interested in more readable regexes, do yourself a huge favor and investigate the /x regex modifier.
Update 2: Fixed small, cosmetic-only formatting glitch in first two code examples.
Give a man a fish: <%-{-{-{-<
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Delimiters in Regexp::Common
by Veltro (Hermit) on May 07, 2018 at 11:15 UTC | |
by AnomalousMonk (Archbishop) on May 07, 2018 at 14:46 UTC | |
by Veltro (Hermit) on May 07, 2018 at 23:02 UTC | |
by AnomalousMonk (Archbishop) on May 08, 2018 at 20:57 UTC | |
by swl (Prior) on May 08, 2018 at 09:27 UTC | |
by Veltro (Hermit) on May 08, 2018 at 10:40 UTC | |
|