I have the following string:
someTxt="ABC -type X | aas < ISCO | ABB | TTI > kjhkjh"
I want to convert it into the following:
ABC -type X | aas < ISCO \| ABB \| TTI > kjhkjh
I am trying to do this in two steps (perhaps it can be better done in one!), as follows:
htmlTagTxt = re.sub(r'\<(.*)\>', r'< \1 >', someTxt)
print (htmlTagTxt)
This gives the following output:
ABC -type X | aas < ISCO | ABB | TTI > kjhkjh
Now I want to add the backslashes before the '|' characters.
cleanedHtmlTagTxt = re.sub(r'(\|)',, r'\\\1', htmlTagTxt)
print (cleanedHtmlTagTxt)
This gives the following output:
ABC -type X \| aas < ISCO \| ABB \| TTI > kjhkjh
However, I want to only add a backslash where the '|' character is inside < and > So the first '|' character just after '-type X' should not be changed. Unfortunately, I do not understand the syntax needed to indicate this. Can someone explain how to do this and a bit of the logic behind it ?