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
    [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.
    Ernesto, Feb 7, 2006
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jay Douglas

    Custom Regular Expressions in ASP.net

    Jay Douglas, Nov 2, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    591
    mikeb
    Nov 3, 2003
  2. Jay Douglas
    Replies:
    0
    Views:
    582
    Jay Douglas
    Aug 15, 2003
  3. Ernesto

    tricky regular expressions

    Ernesto, Feb 7, 2006, in forum: Python
    Replies:
    7
    Views:
    265
    Elezar Simeon Papo
    Feb 8, 2006
  4. Replies:
    9
    Views:
    517
    CBFalconer
    Apr 25, 2006
  5. Noman Shapiro
    Replies:
    0
    Views:
    215
    Noman Shapiro
    Jul 17, 2013
Loading...

Share This Page