tricky regular expressions

Ernesto erniedude at gmail.com
Tue Feb 7 16:01:40 EST 2006


I'm trying to get the right syntax for my regular expression.  The
string I'm trying to parse is:


# myString
[USELESS DATA]
Request: Play
[USELESS DATA]
Name:  David Dude
[USELESS DATA]
Request: Next
[USELESS DATA]
Name: Ernesto Python User
....

# Right now, I'm using the following code:

pattern_Name= '''(?x)
    Title:\s+(.+)
'''
names = re.findall(pattern_Name, myString)
print names

This captures all of the names, but I want an added requirement:
Only capture names which are followed (not necessarily immediately) by
"Request: Play" or "Request: Next".  I guess the regular expression
would look something like:

'''(?x)
    ["Request: Play" OR "Request: Next"][intermediate
data]Title:\s+(.+)
'''
I didn't see any RE constructs like this in the docs, but I have a
feeling it's possible.




More information about the Python-list mailing list