in reply to Regex::Reverse tricky test cases

Why would you want to reverse a regex? Isn't $string =~ reverse(qr/.../) the same as reverse(reverse($string) =~ qr/.../);?

  • In general, if you think something isn't in Perl, try it out, because it usually is. :-)
  • "What is the sound of Perl? Is it not the sound of a wall that people have stopped banging their heads against?"

Replies are listed 'Best First'.
Re^2: Regex::Reverse tricky test cases
by Roy Johnson (Monsignor) on May 17, 2005 at 13:11 UTC
    sexeger.

    Some patterns — notably those with negative lookbehinds, which cannot be variable-length, but also others — work better backwards. Yes, you have to reverse the string to be matched, as well as the regex, and then you have to reverse whatever you captured. Sometimes it's still a win.


    Caution: Contents may have been coded under pressure.