Regex y grouping

Ferran Fontcuberta <[email protected]>
Newsgroups gmane.comp.python.general.castellano
Message-ID <1248795635.2432.29.camel@localhost>
Buenas tardes;

Me gustaría poder utilizar algo tal que así:

def func(p):
	print p
	return p

re.sub('test(\d)', func(r'\1'), 'test0')

Pero veo que no es posible; la conversión de \1 a aquello a que hace
match parece ser que sólo funciona dentro de la expresión regular.

¿Alguna idea de cómo hacerlo?

Por si a alguien le interesa, es una paja mental, lo que quiero hacer
es:

def parseImg(img):
	imgs.append(img)
	return 'cid:'+img

print re.sub(
	'(<img[^(?:src)]* src=")([^"]*)"',
	r'\1'+parseImg(r'\2')+'"',
	i.text
	)

Y sí, se que debería hacerlo con un parser html al estilo BeatifulSoup,
teóricamente; pero solo son dos imagenes; no creo que merezca la pena
cargar BS para ello.

Gracias! :)

_______________________________________________
Lista de correo Python-es 
http://listas.aditel.org/listinfo/python-es
FAQ: http://listas.aditel.org/faqpyes
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.