in reply to Re^4: Delimiters in Regexp::Common (updated)
in thread Delimiters in Regexp::Common
Regexp::Common returns regexp objects, so one can drop the outer // and it will compile.
print "P2 has path\n" if ($P2 =~ $RE{delimited}{ -delim => '/' } ); print "P2 has path\n" if ($P2 =~ $RE{delimited}{ -delim => '\/' } );
Then the escaping becomes a consideration.
use 5.026; use Regexp::Common qw[ delimited ]; say '\/'; say $RE{delimited}{ -delim => '\/' }; say '\\/'; say $RE{delimited}{ -delim => '\\/' }; say '\\\/'; say $RE{delimited}{ -delim => '\\\/' }; say '\\\\/'; say $RE{delimited}{ -delim => '\\\\/' };
produces
\/ (?:(?|(?:\\)(?:[^\\]*(?:(?:\\\\)[^\\]*)*)(?:\\)|(?:\/)(?:[^\\\/]*(?:\\ +.[^\\\/]*)*)(?:\/))) \/ (?:(?|(?:\\)(?:[^\\]*(?:(?:\\\\)[^\\]*)*)(?:\\)|(?:\/)(?:[^\\\/]*(?:\\ +.[^\\\/]*)*)(?:\/))) \\/ (?:(?|(?:\\)(?:[^\\]*(?:(?:\\\\)[^\\]*)*)(?:\\)|(?:\\)(?:[^\\]*(?:(?:\ +\\\)[^\\]*)*)(?:\\)|(?:\/)(?:[^\\\/]*(?:\\.[^\\\/]*)*)(?:\/))) \\/ (?:(?|(?:\\)(?:[^\\]*(?:(?:\\\\)[^\\]*)*)(?:\\)|(?:\\)(?:[^\\]*(?:(?:\ +\\\)[^\\]*)*)(?:\\)|(?:\/)(?:[^\\\/]*(?:\\.[^\\\/]*)*)(?:\/)))
It also appears that Regexp::Common does not de-duplicate the character sequence before it builds the regexp, as the regexps become more complicated as the sequences increase in length.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: Delimiters in Regexp::Common (updated)
by Veltro (Hermit) on May 08, 2018 at 10:40 UTC | |
by swl (Prior) on May 08, 2018 at 12:30 UTC |