I need to replace numbers (corners) that occur within a longer string that all look similar to this:
[ 17 plane_17 \ 23 25 17 99 150 248 \ noname ]
My function takes an "old" number to be replaced with a "new" number, and e.g. if that old number is 17 and the new is 19, then the outcome should be:
[ 17 plane_17 \ 23 25 19 99 150 248 \ noname ]
Note that only the numbers within \ \ should be replaced (these could also be / / ).
To do this I tried to set up a regex substitution with the intention of avoiding numbers outside of \ \ or / /:
newplane = re.compile(r"[^[_] (" + str(oldcorner) + ")").sub(str(newcorner), oldplane)
I quickly realised that this doesn't work since regex searches from the start of the line and then fails if it doesn't match the pattern.
There must be some clever way of doing it still that I don't know about.. Any suggestions?