如何在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