Don't ask to ask, just ask | |
PerlMonks |
Re: Matching string containing values between 0 and 100 inclusiveby grinder (Bishop) |
on Mar 18, 2009 at 08:41 UTC ( [id://751396]=note: print w/replies, xml ) | Need Help?? |
perl -MRegexp::Assemble -le 'print Regexp::Assemble->new->add(0..100)->as_string' ...produces... (?:1(?:[123456789]|0?0)?|2\d?|3\d?|4\d?|5\d?|6\d?|7\d?|8\d?|9\d?|0)This could be simplified by gathering the 2\d?, 3\d?... subpatterns and factoring them into [2-9]\d?, but that would be less efficient since character classes are slower, and in 5.10 this would bypass demerphq's trie optimisation. On the plus side, while it will examine all the 10 primary alternatives during a fail, it's failing on EXACT matches, which is fast. This lesson was brought to you by Stupid Regexp Trick I Can Play. • another intruder with the mooring in the heart of the Perl
In Section
Seekers of Perl Wisdom
|
|