[Tutor] regex eats even when not hungry

2007-02-16 Thread Thomas
I have the following mostly working function to strip the first 4 digit year out of some text. But a leading space confounds it for years starting 20..: import re def getyear(text): s = (?:.*?(19\d\d)|(20\d\d).*?) p = re.compile(s,re.IGNORECASE|re.DOTALL) #|re.VERBOSE y =

Re: [Tutor] regex eats even when not hungry

2007-02-16 Thread Kent Johnson
Thomas wrote: I have the following mostly working function to strip the first 4 digit year out of some text. But a leading space confounds it for years starting 20..: import re def getyear(text): s = (?:.*?(19\d\d)|(20\d\d).*?) p = re.compile(s,re.IGNORECASE|re.DOTALL)