in reply to Re^3: Return string that starts and ends with specific characters
in thread Return string that starts and ends with specific characters

Yes regexes are optimized, if there is a leading or trailing string it's taken into consideration ( I'm to lazy to proof it with re deparse)

but this looks like a fortunate bug, because ^ is a metacharacter in some positions, it's treated differently.

Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Je suis Charlie!

  • Comment on Re^4: Return string that starts and ends with specific characters

Replies are listed 'Best First'.
Re^5: Return string that starts and ends with specific characters
by LanX (Saint) on Aug 19, 2016 at 21:56 UTC
    > but this looks like a fortunate bug, because ^ is a metacharacter in some positions, it's treated differently.

    I finally understood that it's not a bug, because ^ is always a metacharacter, in order to match a literal ^ one needs to escape it

    And "Match the beginning of the line" will always fail unless modifiers like /m are used

    DB<1> p "a^b" =~ /a^b/ DB<2> p "a^b" =~ /a\^b/ 1 DB<3> p "\nb" =~ /^b/m 1

    Cheers Rolf
    (addicted to the Perl Programming Language and ☆☆☆☆ :)
    Je suis Charlie!