Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/351.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 - Fatal编程技术网

如何在Python中重新匹配或搜索数字

如何在Python中重新匹配或搜索数字,python,Python,我想在第一个小数点后匹配精确的两位数。所以在字符串中我没有.12,但它仍然匹配 我在这里犯了什么错误 import re str = "100.13.1" ##if(re.match("^100\.[6|7|8|9|10|11|12]", str)): if(re.search("^100\.[6|7|8|9|10|11|12]", str)): print("[Quit], Matches") else: print("[info], Not match") 试着这样做: import

我想在第一个小数点后匹配精确的两位数。所以在字符串中我没有
.12
,但它仍然
匹配

我在这里犯了什么错误

import re

str = "100.13.1"
##if(re.match("^100\.[6|7|8|9|10|11|12]", str)):
if(re.search("^100\.[6|7|8|9|10|11|12]", str)):
 print("[Quit], Matches")
else:
 print("[info], Not match")
试着这样做:

import re

patt = r'100\.(6|7|8|9|10|11|12)'
data = '100.13.1'

if re.match(patt, data):
    print('[Quit], Matches')
else:
    print('[info], Not match')
或者,此模式将匹配从
6
12
的数字:

r'100\.([6-9]|1[0-2])'

您能否提供一系列可接受和不可接受的输入?你的文章有点晦涩。括号
[]
用于字符集<代码>[6 | 7 | 8 | 9 | 10 | 11 | 12]
归结为字符
0126889
如果(重新匹配(r'10\.(6 | 7 | 8 | 9 | 10 | 11 | 12),str)):
I缺失
r