About 10 months ago, as of this writing, a bug for Regexp::Common was entered regarding a lone decimal point matching the real number regex. Here's an example:
perl -MRegexp::Common -le 'print "." =~ $RE{num}{real}'And that dutifully prints "1" because of the bug. I need to figure out how to get that regular expression to fail. But there's a problem. I need to pass the regular expression to another piece of code and it's important that I need to have that regex fail within the regular expression. In other words, I can't do this:
if ('.' ne $_ && /$RE{num}{real}/) { ... }Since this bug was reported 10 months ago, I'm not sanguine about it being fixed any time soon and I need to solve this problem now. Either I can decide not to use the Regexp::Common regex for this one match or I can force the regex to fail. The former option is the one I'm going with, but I was curious as to why my code to force the regex to fail didn't work (note that what follows has some extra stuff, but it mirrors exactly what I need).
#!/usr/bin/perl use strict; use warnings; use Data::Dumper; use Regexp::Common; use constant SUCCEED => qr{(?=)}; use constant FAIL => qr{(?!)}; my $QUOTED = $RE{quoted}; my $NUM = $RE{num}{real}; my $VALUE = do { use re 'eval'; qr/(?:$QUOTED|$NUM)(??{'.' eq $+ ? FAIL : SUCCEED})/; }; my $text = 'name => "foo", fav.num => 3'; my @text = split /($VALUE)/ => $text; print Dumper \@text;
That prints:
$VAR1 = [ 'name => ', '"foo"', ', fav', '.', 'num => ', '3' ];
What I want it to print is:
$VAR1 = [ 'name => ', '"foo"', ', fav.num => ', '3' ];
Because of the nature of the code (using the lexer from Higher Order Perl's chapter 8, if you're curious), I can't change how the split line operates. I pass regexes to the split and I need the regex to fail at that time. Can anyone help fix the first regex or tell me why my attempt at failing it is broken? (I've also tried the $^N variable, but no love.) I'd prefer to fix my code as I'd like to rely on the Regexp::Common module, but I also know that I'm using experimental features.
Or maybe there's something really simple that I haven't seen.
Cheers,
Ovid
New address of my CGI Course.
In reply to Forcing a regex to fail by Ovid
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |