+ 1

How use the re.sub(pattern,replace,string) to replace && by and and || by or and both have space on both side ??

4th Jan 2020, 8:04 AM
AARTI SHELAR
AARTI SHELAR - avatar
12 odpowiedzi
+ 3
AARTI SHELAR the && is missing because it loses its spaces, i.e. its spaces are captured.
4th Jan 2020, 8:31 AM
SergeiRom
+ 3
AARTI SHELAR maybe s=re.sub(r"\s&&(?=\s)"," and ",s) print(re.sub(r"\s\|\|(?=\s)"," or ",s))
4th Jan 2020, 9:09 AM
SergeiRom
+ 2
re.sub(r'( && )|( \|\| )', lambda m: ' and ' if '&&' in m.group() else ' or ', 'test && ||') maybe
4th Jan 2020, 8:21 AM
SergeiRom
4th Jan 2020, 8:12 AM
AARTI SHELAR
AARTI SHELAR - avatar
0
No ? I want " && " character replace by " and " note that there is space on both side
4th Jan 2020, 8:26 AM
AARTI SHELAR
AARTI SHELAR - avatar
0
Sergei Romanov I know I was try what you say let check it
4th Jan 2020, 8:41 AM
AARTI SHELAR
AARTI SHELAR - avatar
4th Jan 2020, 8:41 AM
AARTI SHELAR
AARTI SHELAR - avatar
0
s = re.sub(r"&&", " and ", s) s = re.sub(r"\|\|", " or ", s)
4th Jan 2020, 8:56 AM
Tibor Santa
Tibor Santa - avatar
0
No
4th Jan 2020, 9:01 AM
AARTI SHELAR
AARTI SHELAR - avatar
4th Jan 2020, 9:01 AM
AARTI SHELAR
AARTI SHELAR - avatar
0
r"" just covert into row string
4th Jan 2020, 9:03 AM
AARTI SHELAR
AARTI SHELAR - avatar
4th Jan 2020, 9:25 AM
AARTI SHELAR
AARTI SHELAR - avatar