Regex problem ...

logistix logstx at bellatlantic.net
Wed Mar 27 17:35:07 EST 2002


I don't think you can hook a function inside a regex in Python.

You probably want to use tagImg.match or tagImg.search to generate a match
object, and use that object to build a new string.  Of course this can get
annoying with really big HTML docs.  Check out the standard module
HTMLparser if you want to break the docs into smaller chunks before
processing.

--
-

"Barghest" <barghest at wanadoo.fr> wrote in message
news:a7s3lu$qfq$1 at reader1.imaginet.fr...
> Hello,
> import re
> tagImg = re.compile( r"""(<img\s+src=")\.\./Images/([^"]*)("[^>]*>)""",
> re.IGNORECASE | re.MULTILINE | re.DOTALL )
>
> Wanna match ... <img src="../images/FOO.gif" height="12" etc...> and
replace
> it by
> <img src="foo.gif" height="12" ...>
>
> the problem is that i don't know how to lowercase the \g<2> part
> bp2.write( tagImg.sub( '\g<1>\g<2>\g<3>', buff ) )
>
> I tried
> tagImg.sub( string.lower( '\g<1>\g<2>\g<3>' ), buff )
> but it doesen't work ..
>
> Any idea ?
>
>





More information about the Python-list mailing list