... the next lines do not compile: ...
I've played around with this some more and I'm coming to the conclusion that this has little or nothing to do with Regexp::Common::delimited and more to do with the use of a regex delimiter character within the regex pattern. The following works as I expect with any of
'\/' '\\/' '\\\/' '\\\\/' '\\\\\/' '\\\\\\/'
as the -delim delimiter specification:
Both m: ... : and the balanced m{ ... } (my personal preference per TheDamian's regex PBPs) yield the same results.c:\@Work\Perl\monks\Veltro>perl -wMstrict -le "use Regexp::Common qw(delimited); ;; for my $s (qw( a/b/c a\b\c /a/ \a\ a//b a\\\\b // \\\\ a/b a\b a/b\c a\b/c a/ /a a\ \a / \ )) { print qq{'$s' }, $s =~ m{$RE{delimited}{ -delim => '\/' }} ? '' : 'NO ', ' match'; } " 'a/b/c' match 'a\b\c' match '/a/' match '\a\' match 'a//b' match 'a\\b' match '//' match '\\' match 'a/b' NO match 'a\b' NO match 'a/b\c' NO match 'a\b/c' NO match 'a/' NO match '/a' NO match 'a\' NO match '\a' NO match '/' NO match '\' NO match
For a / ... / delimited match with the code above, the -delim strings:
IIRC from previous regex compilation discussions (and please don't ask me for a citation :), I think what's happening here is that the regex parser looks for the end of a regex using various heuristics as soon as it sees that a regex has opened, and in this case, it sees the forward-slash at the end of the first '\\/' (or whatever) single-quoted string and sometimes mistakes it for the regex terminal delimiter. The Perl parser looks for single-quoted strings thereafter, and goes off the rails when it sees that a final single-quote is unmatched. Or something like that... Anyway, don't use // regex delimiters here.
Update: The "premature regex termination detection" theory is supported if the
my $rx = qr{ $RE{'\\\\/'} $RE{'\\\/'} $RE{'\\/'} $RE{'\/'} $RE{'/'} };
regex from Re^3: Delimiters in Regexp::Common (updated) is re-written with qr/ ... / instead: the "Can't find string terminator "'" anywhere ..." compilation error results.
Give a man a fish: <%-{-{-{-<
In reply to Re^5: Delimiters in Regexp::Common (updated)
by AnomalousMonk
in thread Delimiters in Regexp::Common
by rongrw
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |