in reply to Matching date range with pure regex

I like the following one. If that does not work please let me know. I am not an expert in regex but want to become one!

while (<DATA>) { chomp; if (/^(19|20)([5-9]|[0-5])([0-9])$/) { print "it matches for $_\n"; } } __DATA__ 1950 2050 2001 2009 2000

It says: first two digits should be 19 or 20, third digit can go from 5 to 9 or 0 to 5 and the fourth digit is 0-9.

Replies are listed 'Best First'.
Re: Re: Matching date range with pure regex
by MCS (Monk) on Feb 17, 2004 at 18:20 UTC

    (5-9|0-5)
    That doesn't really make sense... it's the same as 0-9. Your regex can be simplified to: /^(19|20)\d\d$/ Which doesn't meet the requirements.

    If you really want to become a regex master, the first step to enlightenment is to read "Mastering Regular Expressions" by Jeffrey Friedl. The link is to the publishers site (O'Reilly) but you can get it just about anywhere. That book taught me everything I know about regular expressions.