regex problem

Thomas Guettler guettli at thomas-guettler.de
Tue Jul 26 07:07:28 EDT 2005


Am Tue, 26 Jul 2005 09:57:23 +0000 schrieb Odd-R.:

> Input is a string of four digit sequences, possibly
> separated by a -, for instance like this
> 
> "1234,2222-8888,4567,"
> 
> My regular expression is like this:
> 
> rx1=re.compile(r"""\A(\b\d\d\d\d,|\b\d\d\d\d-\d\d\d\d,)*\Z""")

Hi,

try it without \A and \Z

import re
rx1=re.compile(r"""(\b\d\d\d\d,|\b\d\d\d\d-\d\d\d\d,)""")
print rx1.findall("1234,2222-8888,4567,")
# --> ['1234,', '2222-8888,', '4567,']

 Thomas

-- 
Thomas Güttler, http://www.thomas-guettler.de/





More information about the Python-list mailing list