Fwd: small problem with re.sub

Discussion in 'Python' started by Sergio Correia, Jan 31, 2008.

  1. See this:
    http://www.regular-expressions.info/python.html
    (the Search and Replace part)

    You are referring to the group as "(?P=id)", when you should be using
    r"\g<name>".

    HTH,
    Sergio


    On Jan 30, 2008 10:01 PM, Astan Chee <> wrote:
    > Hi,
    > I have a html text stored as a string. Now I want to go through this
    > string and find all 6 digit numbers and make links from them.
    > Im using re.sub and for some reason its not picking up the previously
    > matched condition. Am I doing something wrong? This is what my code
    > looks like:
    > htmlStr = re.sub('(?P<id>\d{6})','<a
    > href=\"http://linky.com/(?P=id).html\">(?P=id)</a>',htmlStr)
    > It seems that it replaces it alright, but it replaces it literally. Am I
    > not escaping certain characters?
    > Thanks again for the help.
    > Cheers
    >
    > Animal Logic
    > http://www.animallogic.com
    >
    > Please think of the environment before printing this email.
    >
    > This email and any attachments may be confidential and/or privileged. If you are not the intended recipient of this email, you must not disclose or use the information contained in it. Please notify the sender immediately and delete this document if you have received it in error. We do not guarantee this email is error or virus free.
    >
    >
    >
    > --
    > http://mail.python.org/mailman/listinfo/python-list
    >
     
    Sergio Correia, Jan 31, 2008
    #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. THY
    Replies:
    1
    Views:
    411
    Steve C. Orr, MCSD
    Aug 19, 2003
  2. Davide Carboni
    Replies:
    0
    Views:
    382
    Davide Carboni
    Dec 18, 2003
  3. Ben
    Replies:
    2
    Views:
    954
  4. Astan Chee

    small problem with re.sub

    Astan Chee, Jan 31, 2008, in forum: Python
    Replies:
    1
    Views:
    297
    Mark Tolonen
    Jan 31, 2008
  5. Lawrence D'Oliveiro

    Death To Sub-Sub-Sub-Directories!

    Lawrence D'Oliveiro, May 5, 2011, in forum: Java
    Replies:
    92
    Views:
    2,166
    Lawrence D'Oliveiro
    May 20, 2011
Loading...

Share This Page