text = '3 * 6'
我想要的结果:3,*,6没有空格
目前我有:
pattern = r'(\d+) (\*) (\d+)'
result=re.split(pattern, text)
result
output: ['', '3', '*', '6', '']
text = '3 * 6'
我想要的结果:3,*,6没有空格
目前我有:
pattern = r'(\d+) (\*) (\d+)'
result=re.split(pattern, text)
result
output: ['', '3', '*', '6', '']
You should use
findall
, notsplit
:换句话说:一个或多个数字,后跟可选的空格,然后是一个运算符,然后是可选的空格,再跟一个或多个数字。