Using Python regex find and replace to add HTML tags around raw text
<p>I'm building a simple web app using Flask and I want to know if it is possible to use regex to find and replace the numbers in Fe2O3 + CO -> Fe + CO2 and surround them with the sub HTML tag so it becomes Fe<sub>2</sub>O<sub>3</sub> + CO -> Fe + CO<sub>2</sub> when displayed in HTML.</p>

<p>Try something like this, Here <code>a</code> is your input string. Implemented without using regex.</p>

<pre><code>In [1]: a = 'Fe2O3 + CO -&gt; Fe + CO2'
In [2]: ''.join(['&lt;sub&gt;'+i+'&lt;/sub&gt;' if i.isdigit() else i for i in a])
Out[1]: 'Fe&lt;sub&gt;2&lt;/sub&gt;O&lt;sub&gt;3&lt;/sub&gt; + CO -&gt; Fe + CO&lt;sub&gt;2&lt;/sub&gt;'
</code></pre>

python regex