http://qs321.pair.com?node_id=751396


in reply to Matching string containing values between 0 and 100 inclusive

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