|laziness, impatience, and hubris|
A Regex to identify Regex's / Compiling a regexby knowmad (Monk)
|on Sep 19, 2002 at 21:14 UTC||Need Help??|
knowmad has asked for the
wisdom of the Perl Monks concerning the following question:
I am working on some modifications to the Data::FormValidator module and have a couple of questions about regex's. The first is regarding a gnarly regex which I am trying to understand and the second is about compiling a regex into an anonymous subroutine.
I've put the regex which matches regex's into extended format and started adding some comments to figure out what this beast is doing. Any additional info would be helpful.
The Data::FormValidator allows users to submit custom regex's for checking input. It does this by compiling the regex into an anonymous subroutine (see code below). I have discovered a curious anomaly in the evaluation phase of the subroutine when dealing with a regex that contains a \\ (an escaped backslash). Basically, one regex ($constraint_good) will compile and run while the second will not compile. The only difference between the two is the placement of the \\. The working regex puts this at the beginning; the bad one has this at the end (don't even ask how I figured this out; one of those flukes). See the code below for details.
When you run this snippet you should receive the following (tested under Perl 5.6.1 on WinNT4 and Debian 3.0):
Your wisdom or comments are greatly appreciated.