So I have a function that takes a string, iterates over a set of characters and returns a string with a backslash added to all the occurences of any character in that particular string:
def re_escape(string):
res = "|\^&+\-%*/=!>"
for i in res:
if i in string:
a = string.split(i)
adjusted = ""
for y in a:
adjusted+="\\"+i+y
adjusted = adjusted[2:]
string = adjusted
print(string)
return string
Giving this function the string " <br>"
returns " <br\>"
, as desired.
However, going back to the part of the program calling this function and receiving the string as a return value, trying to print it results in " <br\\>"
being printed. Is there any way to prevent it from adding the second undesired backslash?