I have the following text:
string = "<i>R</i> subspace <i>{V.</i> generated by <i>{v<sub>1</sub>,...,v<sub>i</sub></i>, "
A careful reader might notice that there are two brackets missing. I was wondering, how this could be fixed using Python?
The expected output would be:
the <i>R</i> subspace <i>{V.}</i> generated by <i>{v<sub>1</sub>,...,v<sub>i</sub>}</i>,
One could:
- Check: Is there a bracket after
<i>? - If yes -> Is there a bracket before
</i>?
How can I code this?
Edit
I have found this code, that can tell you if the brackets match or not.
re.subwith a callablereplparam that ensures there's a final '}' for any chunk with an initial '{'). But the second case falls under stackoverflow.com/a/1732454repl. Sorry to bother you... I see that I can do: re.sub(r'<I>, SOMETHING, string)