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

2006-02-24 Thread Larry Bates
[EMAIL PROTECTED] wrote: > 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 i

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

2006-02-24 Thread plahey
Doesn't this do what you want? import re DATE_TIME_RE = re.compile(r'((\d{2}\/\d{2}\/\d{4})|(\d{2}:\d{2}))<\/td>') test = '04/01/2006' \ 'Wednesday' \ ' ' \ '09:14' \ '12:44' \ '12:50' \ '17:58' \ ' ' \ ' '

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

2006-02-24 Thread Paul McGuire
Here's a (surprise!) pyparsing solution. -- Paul (Get pyparsing at http://pyparsing.sourceforge.net.) data = [ """04/01/2006Wednesday 09:1412:4412:5017:5808:14""", """03/01/2006TuesdayAnnual_Holiday08:00""" ] from pyparsing import * startTD,endTD = makeHTMLTags("TD") startTD = start

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/py

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

2006-02-24 Thread johnzenger
You can check len(sanesplit) to see how big your list is. If it is < 2, then there were no 's, so move on to the next line. It is probably possible to do the whole thing with a regular expression. It is probably not wise to do so. Regular expressions are difficult to read, and, as you discover

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 ac

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

2006-02-24 Thread johnzenger
There's more to re than just sub. How about: sanesplit = re.split(r"||", text) date = sanesplit[1] times = times = [time for time in sanesplit if re.match("\d\d:\d\d", time)] ... then "date" contains the date at the beginning of the line and "times" contains all your times. -- http://mail.pyth

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 wo