#1
  1. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    206
    Rep Power
    12

    regular expression


    Hi all,

    short question concering a regular expression pattern.
    Code:
    line = '1	"bla \"bla\" $%1!\n" $ just "a" test'
    rexEntry = re.compile('^(\d+)\s"(.*)" *(\$.*)?')
    mo = rexEntry.match(line)
    print mo.groups()
    With this I get the following result:
    Code:
    ('1', 'bla \"bla\" $%1!\n" $ just "a', None)
    But that what I want is:
    Code:
    ('1', 'bla \"bla\" $%1!\n', '$ just "a" test')
    Can someone give me a hint?

    Thanks in advance!
  2. #2
  3. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    This works for me... with the example above.

    Code:
    ^([0-9]+)\t"(.+)"\s(\$.+?)$
    Note: If you use this with match you shouldnt have to have the ^ at the beginning.

    Hope this helps,

    Mark.
    programming language development: www.netytan.com Hula

  4. #3
  5. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    206
    Rep Power
    12
    Thank you for your reply.
    Your code works for the example above but there are still cases in my problem that can't be matched with this pattern.
    I solved the problem by specifying two patterns and combined them with |
    That works now for me...

    ... I always use ^ if I want to find a string at the beginning. I know that just "match" will do it also but ...
    ... I don't know ... habit

IMN logo majestic logo threadwatch logo seochat tools logo