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.
re.sub(r"(?<!\S)&&(?!\S)", "and", text)? You only have a trailing space that overlaps.[ ]&&(?=[ ])replace ` and` this way endchar can be reuse (overlap) adjacent ` &&` if needed. of course you can get fancy and im so great stuiff afnd do assertunz back forward and upside down, but that is up to you