tricky regular expressions

Discussion in 'Python' started by Ernesto, Feb 7, 2006.

  1. Ernesto

    Ernesto Guest

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

    # myString
    Request: Play
    Name: David Dude
    Request: Next
    Name: Ernesto Python User

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

    pattern_Name= '''(?x)
    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:

    ["Request: Play" OR "Request: Next"][intermediate
    I didn't see any RE constructs like this in the docs, but I have a
    feeling it's possible.
    Ernesto, Feb 7, 2006
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.