in reply to Delimiters in Regexp::Common

I would like to sincerely thank everyone who added their comments on this topic. A lot of very in-depth detail about regexes was posted - thank you.

Initially I thought the following Regexp::Common expression was a great solution,

$P2 =~ /$RE{delimited}{-delim => '\\\/'}/

But then AnomalousMonk posted this expression,

$P2 =~ m{$RE{delimited}{-delim => '\/'}}
Its brilliant, and definitely my preferred choice because it lists the actual characters that are used as delimiters. The lesson I've learnt here is that if the delimiter character(s) are the same as those enclosing the regex, then choose a different set of characters to enclose the regex.

Once again, thank you for all the helpful posts!
- Ron.

Replies are listed 'Best First'.
Re^2: Delimiters in Regexp::Common
by AnomalousMonk (Archbishop) on May 09, 2018 at 15:28 UTC
    The lesson ... if the delimiter character(s) are the same as those enclosing the regex ...

    I think that the lesson should be that if a regex pattern contains any character that is the same as the regex delimiters, care should be exercised. Usually, it's enough to escape such embedded characters in the normal way, but in this particular case, any escapology does not take place within the normal context of regex interpolation, and that leads to some unexpected quirky behavior.


    Give a man a fish:  <%-{-{-{-<