Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.python
Fwd: small problem with re.sub
Sergio Correia
1/31/2008 3:39:00 AM
See this:
http://www.regular-expressions.info/p...
(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 <stanc@al.com.au> 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://...
(?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.anima...
>
> 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/p...
>
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Fwd: small problem with re.sub
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password