regex problem

Duncan Booth duncan.booth at invalid.invalid
Tue Jul 26 09:29:28 EDT 2005


John Machin wrote:

> So here's the mean lean no-flab version -- you don't even need the 
> parentheses (sorry, Thomas).
> 
> >>> rx1=re.compile(r"""\b\d\d\d\d,|\b\d\d\d\d-\d\d\d\d,""")
> >>> rx1.findall("1234,2222-8888,4567,")
> ['1234,', '2222-8888,', '4567,']

No flab? What about all that repetition of \d? A less flabby version:

>>> rx1=re.compile(r"""\b\d{4}(?:-\d{4})?,""")
>>> rx1.findall("1234,2222-8888,4567,")
['1234,', '2222-8888,', '4567,']




More information about the Python-list mailing list