tricky regular expressions

Ernesto erniedude at gmail.com
Tue Feb 7 16:02:18 EST 2006


So regular expressions have been good to me so far, but now my problem
is a bit trickier.  The string I'm getting data from looks like this:

myString =
[USELESS DATA]
Request : Play
[USELESS DATA]
Title: Beethoven's 5th
[USELESS DATA]
Request : next
[USELESS DATA]
Title:  song #2
.....

I'm using this code to search myString:
....
pattern = '''(?x)
    Title:\s+(.+)
'''
Titles = re.findall(pattern, myString)

....
The problem is that I only want the "Titles" which are either:

a) Followed by "Request : Play"
b) Followed by "Request : next"

I'm not sure if I should use RE's or some other mechanism.  Thanks




More information about the Python-list mailing list