Regular expression fun. Repeated matching of a group Q

2006-02-24 Thread matteosartori
Hi all,

I've spent all morning trying to work this one out:

I've got the following string:

04/01/2006Wednesday 09:1412:4412:5017:5808:14

from which I'm attempting to extract the date, and the five times from
into a list. Only the very last time is guaranteed to be there so it
should also work for a line like:

03/01/2006TuesdayAnnual_Holiday08:00

My Python regular expression to match that is currently:

digs = re.compile(
r'(\d{2}\/\d{2}\/\d{4}).*?(?:(\d+\:\d+)).*$' )

which first extracts the date into group 1
then matches the tags between the date and the first instance of a time
into group 2
then matches the first instance of a time into group 3
but then group 4 grabs all the remaining string.

I've tried changing the time pattern into

(?:(\d+\:\d+))+

 but that doesn't seem to mean "grab one or more cases of the previous
regexp."

Any Python regexp gurus with a hint would be greatly appreciated.

M@

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Regular expression fun. Repeated matching of a group Q

2006-02-24 Thread matteosartori
Thanks,

The date = sanesplit[1] line complains about the "list index being out
of range", which is probably due to the fact that not all lines have
the  in them, something i didn't explain in the previous post.

I'd need some way of ensuring, as with the pattern I'd concocted, that
a valid line actually starts with a  containing a / separated date
tag.

As an aside, is it not actually possible to do what I was trying with a
single pattern or is it just not practical?

M@

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Regular expression fun. Repeated matching of a group Q

2006-02-24 Thread matteosartori
Yes, it's easier to read without a doubt. I just wondered if i was
failing to do what i was trying to do because it couldn't be done or
because i hadn't properly understood what i was doing. Alas, it was
probably the latter.

Thanks for your help,

M@

-- 
http://mail.python.org/mailman/listinfo/python-list