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_String_Digits - Fatal编程技术网

Python 正则表达式查找字符串之间的所有模式

Python 正则表达式查找字符串之间的所有模式,python,regex,string,digits,Python,Regex,String,Digits,我想从如下字符串中匹配介于“000”或\b与“000”或“000”与\b之间的数字: 11101110001011101000000011101010111 我尝试过这样的表达: (?<=000)\d+(?=000) re.findall(r'(?:\b|(?<=000))(\d+?)(?:000|\b)', s) 您可以使用和.findall()方法: In [1]: s = "11101110001011101000000011101010111" In [2]: imp

我想从如下字符串中匹配介于“000”或\b与“000”或“000”与\b之间的数字:

11101110001011101000000011101010111
我尝试过这样的表达:

(?<=000)\d+(?=000)
re.findall(r'(?:\b|(?<=000))(\d+?)(?:000|\b)', s)
您可以使用和
.findall()
方法:

In [1]: s = "11101110001011101000000011101010111"

In [2]: import regex

In [3]: regex.findall(r"(?<=000|^)\d+?(?=000|$)", s)
Out[3]: ['1110111', '1011101', '0', '00011101010111']
[1]中的
:s=“11101110001011101000000011101010111”
在[2]中:导入正则表达式
在[3]:regex.findall(r)(?中,您可以使用和
.findall()
方法:

In [1]: s = "11101110001011101000000011101010111"

In [2]: import regex

In [3]: regex.findall(r"(?<=000|^)\d+?(?=000|$)", s)
Out[3]: ['1110111', '1011101', '0', '00011101010111']
[1]中的
:s=“11101110001011101000000011101010111”
在[2]中:导入正则表达式

在[3]:regex.findall(r)(?中,您可以像这样使用re模块:

(?<=000)\d+(?=000)
re.findall(r'(?:\b|(?<=000))(\d+?)(?:000|\b)', s)

re.findall(r'(?:\b |)(?您可以像这样使用re模块:

(?<=000)\d+(?=000)
re.findall(r'(?:\b|(?<=000))(\d+?)(?:000|\b)', s)

re.findall(r'(?:\b |)(?可能重复的可能重复的它不起作用,我尝试了这个
(?我已经解决了!!谢谢,这是有效的代码
(?它不起作用,我尝试了这个
)(?我已经解决了!!谢谢,这是有效的代码
(?)?