Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.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,我正在使用正则表达式查找未使用0x重新固定的数字序列 例如 我的正则表达式是(?:[^(0x)]\d+,它(在我的头脑中)转换为匹配任何不以0x开头的数字序列。但这不起作用-我错误地做出了什么假设?[^(0x)]在正则表达式中匹配任何非(,0,x,)的字符 使用负回溯: >>> re.findall(r'(?<!0x)\d+\b', '0 0x111 50505 20201 0012') ['0', '11', '50505', '20201', '0012'] 对于不

我正在使用正则表达式查找未使用
0x
重新固定的数字序列

例如

我的正则表达式是
(?:[^(0x)]\d+
,它(在我的头脑中)转换为匹配任何不以
0x
开头的数字序列。但这不起作用-我错误地做出了什么假设?

[^(0x)]
在正则表达式中匹配任何非
0
x
)的字符

使用负回溯:

>>> re.findall(r'(?<!0x)\d+\b', '0 0x111 50505 20201 0012')
['0', '11', '50505', '20201', '0012']

对于不是以[0或x]开头的任何内容,它看起来都是非捕获组

你有没有试着用负面的眼光看后面

(r'(?<!0x)\d+')

(r'(?但我想'11'元素不是真的需要?@Jahaja,啊..我会解决它的。不过,如果你的秒数接近,你会得到+1。
>>> re.findall(r'\b\d+\b', '0 0x111 50505 20201 0012')
['0', '50505', '20201', '0012']
(r'(?<!0x)\d+')