1👍
✅
Why not using str.replace()
or ‘re.subn()’? E.g.:
replaced = markup.replace('<pre>', '<pre class="prettyprint">')
or
replaced = re.subn('(<pre[^>]*)', '\\1 class="prettyprint"', markup)
👤twil
Source:stackexchange.com