#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2001
    Posts
    15
    Rep Power
    0

    Question regular expression


    I was wondering if anyone knows a goods tutorial on using regular expressions. I have gone through the phython manual and tutorial in the supplied documentation but it is not detailed. Also how would I get everthig after the "hello" in this string using the regular expersion module?

    " What a nice day guys. hello it's me Omega "

    thank you
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2004
    Location
    London, England
    Posts
    1,585
    Rep Power
    1373
    There is a tutorial at http://www.amk.ca/python/howto/regex/.

    The book 'Text Processing in Python' by David Mertz has a chapter on regular expressions. You can find a web copy of the book at http://gnosis.cx/TPiP/.

    In answer to your second question:

    Code:
    >>> import re
    >>> s = " What a nice day guys. hello it's me Omega "
    >>> match = re.search(r'hello(.*)', s)
    >>> match.group(1)
    " it's me Omega "
    The regular expression "hello(.*)" will match the "hello", then assign all the text after it to a group, which can then be extracted from the match object.

    Dave - The Developers' Coach
    Last edited by DevCoach; May 21st, 2004 at 10:23 AM.

IMN logo majestic logo threadwatch logo seochat tools logo