Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Re^7: Regex Modification

by AnomalousMonk (Canon)
on Apr 14, 2013 at 07:13 UTC ( #1028604=note: print w/replies, xml ) Need Help??

in reply to Re^6: Regex Modification
in thread Regex Modification

Here is a further simplified (and tested) version of the regex. The  $digits and  $diffs package variables are no longer needed, so I'm a little happier with this version, but it still uses absolute capture group numbering and embedded code. I could perhaps use named captures to get around the numbering problem, but I don't see what I can do about the code.

There are a few more comments that may be helpful, and davido's nice Perl Regular Expression Tester may be enlightening. I may get around to posting a more detailed commentary on the regex in the next couple of days.

my $ndn = qr{ # cannot begin after digit or any differentiator char (?<! \d) (?<! $diff) # begin potential main pattern capture to group 1 ($d_min # begin group 1 with minimum digits ($diff)? # group 2: possible differentiator char # match to max number of digit(s)/single-diff groups (?: \d+ \g{-1} (?= \d)){0,9} # end group 1 (main pattern) capture with minimum digits $d_min) # end group 1 # main pattern cannot be followed by a digit... (?! \d) # ...or by the diff char, or by any diff char if none present (?(2) (?! \g{-1}) | (?! $diff)) # qualify potential main pattern for min/max digits (?(?{ $1 =~ tr/0-9// > 15 || $1 =~ tr/0-9// < 9 }) (*FAIL)) }xms;

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1028604]
talexb mutters, "Those darned cosmic rays.", then gets back to coffee and code. There's plenty of both to go around.

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (8)
As of 2017-04-25 14:50 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (455 votes). Check out past polls.