I have a string in which I need to add a ‘\’ in front of every ‘[‘ or ‘]’, except if the brackets enclose an x like this: ‘[x]’. In the other cases, the brackets will always enclose a number.
Example:
'Foo[123].bar[x]' should become 'Foo\[123\].bar[x]'.
What is the best way to achieve this? Thanks a lot on beforehand.
Something like this ought to work: