Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用正则表达式python拆分字符串_Python_Regex - Fatal编程技术网

使用正则表达式python拆分字符串

使用正则表达式python拆分字符串,python,regex,Python,Regex,我想把这根绳子分成几段 80 x 59 x 53 108 x 98 x 73 任何字符之间可以有任意数量的空格 请帮我解决这个问题 提前感谢使用正向向后看和正向向前看regex: 80 x 59 x 53 and 108 x 98 x 73 您需要打印和。 import re s = '80 x 59 x 53 108 x 98 x 73' print(re.split(r'(?<=\d)\s+(?=\d)', s)) # ['80 x 59 x 53', '108 x 98 x

我想把这根绳子分成几段

80 x 59 x 53 108 x 98 x 73
任何字符之间可以有任意数量的空格

请帮我解决这个问题


提前感谢

使用正向向后看和正向向前看
regex

80 x 59 x 53 and 108 x 98 x 73

您需要打印<代码>和。
import re

s = '80 x 59 x 53 108 x 98 x 73'
print(re.split(r'(?<=\d)\s+(?=\d)', s))

# ['80 x 59 x 53', '108 x 98 x 73']
print(' and '.join(re.split(r'(?<=\d)\s+(?=\d)', s)))

# 80 x 59 x 53 and 108 x 98 x 73