regex problem

Odd-R. oddr at home.no.no
Wed Jul 27 08:29:28 EDT 2005


On 2005-07-26, Duncan Booth <duncan.booth at invalid.invalid> wrote:
>>>> rx1=re.compile(r"""\b\d{4}(?:-\d{4})?,""")
>>>> rx1.findall("1234,2222-8888,4567,")
> ['1234,', '2222-8888,', '4567,']

Thanks all for good advice. However this last expression
also matches the first four digits when the input is more
than four digits. To resolve this problem, I first do a 
match of this,

regex=re.compile(r"""\A(\b\d{4},|\d{4}-\d{4},)*(\b\d{4}|\d{4}-\d{4})\Z""")

If this turns out ok, I do a find all with your expression, and then I get
the desired result.


-- 
Har du et kjøleskap, har du en TV
så har du alt du trenger for å leve

-Jokke & Valentinerne



More information about the Python-list mailing list