in reply to Regular expression pattern matching question
I intially just ran perl -MRegexp::List -le 'print Regexp::List->new->list2re( 4333 .. 9999 )' but that made a larger regex than I liked. Here's what I did by hand. It should be easy to follow how it's constructed.
$rx_4333 = qr/ (?: 4 3 3 [3-9] | 4 3 [4-9] \d | 4 [4-9] \d \d | [5-9] \d \d \d ) $/x
This next regex does the same thing but has less work to do. In the previous example, the different paths would have to retry matching stuff that was already known to be true (the first 4??? vs the second 4???). This does the minimum amount of work.
$rx_4333 = / (?: 4 (?: 3 (?: 3 [3-9] | [4-9] \d ) | [4-9] \d \d ) | [5-9] \d \d \d ) $/x
⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Regular expression patter matching question
by ikegami (Patriarch) on Jan 19, 2006 at 20:03 UTC | |
by diotalevi (Canon) on Jan 19, 2006 at 20:07 UTC | |
|
Re^2: Regular expression patter matching question
by grinder (Bishop) on Jan 19, 2006 at 21:14 UTC | |
by diotalevi (Canon) on Jan 19, 2006 at 21:34 UTC |