New to python, competent in several languages, but not able to see a "dull" way to do the following. I'm sure he screams about regex, but any solution I can come up with (using regex groups and what not) gets really crazy.
So, I have a line with html-like tags that I want to replace with actual html tags.
For instance:
Hello, my name is /bJane/b.
It should become:
Hello, my name is <b>Jane</b>.
It can be combined with [i] talic and [u] nderline:
/iHello/i, my /uname/u is /b/i/uJane/b/i/u.
It should become:
<i>Hello</i>, my <u>name</u> is <b><i><u>Jane</b></i></u>.
Obviously, the direct str.replace will not work, because every second token must be exceeded in advance.
For clarity, if the markers are combos, it always first opens, first closes.
Many thanks!
PS: Before anyone starts to worry, I know that this kind of thing needs to be done with CSS, blah, blah, blah, but I did not write software, I just change its output!
python regex token
Bridgey
source share