🕷 zenspider.com

by ryan davis

Looking for the Ruby Quickref?

Worst Regexp I've Ever Written

Published 2008-01-14 @ 01:26

Tagged thoughts

This was part of a Parse::RecDescent grammar (or it might have been antlr by then) for a QA scripting tool that matched most perl 5 regexps. Note that nearly everything is double backslashed for the parser generator, not as part of the regexp.

    regex           : m/(
                    |   m\\((\\\\\\)|[^\\)])+?\\)
                    |   m\\[(\\\\\\]|[^\\]])+?\\]
                    | m\\\{(\\\\\\\}|[^\\\}])+?\\\}
                    |   m(.)(\\\\\\6|[^\\6])+?\\6)/x
                    | <error>

I’m mainly blogging this because I keep losing it. I think this is the correct unbackslashification:

  m/  (\/(\\\/|[^\/])+?\/
   |  m\((\\\)|[^\)])+?\)
   |  m\[(\\\]|[^\]])+?\]
   |  m\{(\\\}|[^\}])+?\}
   | m(.)(\\\6|[^\6])+?\6)/x

Still gross as hell.