+ 1
How use the re.sub(pattern,replace,string) to replace && by and and || by or and both have space on both side ??
12 Antworten
+ 3
AARTI SHELAR the && is missing because it loses its spaces, i.e. its spaces are captured.
+ 3
AARTI SHELAR maybe
s=re.sub(r"\s&&(?=\s)"," and ",s)
print(re.sub(r"\s\|\|(?=\s)"," or ",s))
+ 2
re.sub(r'( && )|( \|\| )', lambda m: ' and ' if '&&' in m.group() else ' or ', 'test && ||') maybe
0
No ? I want " && " character replace by " and " note that there is space on both side
0
Sergei Romanov I know I was try what you say let check it
0
s = re.sub(r"&&", " and ", s)
s = re.sub(r"\|\|", " or ", s)
0
No
0
r"" just covert into row string