I am trying to find &&
using regex and substitute it with and
using Python.
Here is my regex:
r"(?=( && ))"
test input: x&& &&& && && x || | ||\|| x
, expected output: x&& &&& and and x or | ||\|| x
. My Python code:
import re
input = "x&& &&& && && x || | ||\|| x"
result = re.sub(r"(?=( && ))", " and ", input)
print(result)
My output is: x&& &&& and && and && x || | ||\|| x
. This actually works, but instead of substitution it leaves the original pattern just adds my substitution string when it finds pattern. This is really confusing.