/ / Python: Sub ersetzt kein Ersatzmuster - python, replace

Python: Sub ersetzt kein Ersatzmuster - python, replace

Ich habe diesen Code für etwas, das ein Leben lang scheint, gemacht und kann es scheinbar nicht zum Laufen bringen.

translation = re.sub(""""[a-zA-Z0-9].*?"""", "<b>[what do I put here to copy [a-zA-Z0-9].*?</b>", translation)

Here I"m trying to replace " """ [text] """ " with " <b> [text] </b>. What would I have to put between <b> and </b> to make it copy across the text?

Vielen Dank im Voraus!

Antworten:

2 für die Antwort № 1

Verwenden Sie eine Erfassungsgruppe und verweisen Sie darauf 1:

translation = re.sub(r""""([a-zA-Z0-9].*?)"""", r"<b>1</b>", translation)

0 für die Antwort № 2
translation = re.sub(""""([a-zA-Z0-9]*)"""", r"<b>1</b>", translation)

So ähnlich?