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

I think regex is smart enough to detect no \0 but not ^

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

Replies are listed 'Best First'.
Re^4: Return string that starts and ends with specific characters
by LanX (Saint) on Jun 03, 2016 at 00:26 UTC
    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!

      > 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!