import re
a = "AB01"
m = re.compile(r"([A-Z]{2})(\s?_?\s?)([0-9]{2})") # note raw string
g = m.match(a)
if g:
g = m.match(a).group(1) + "-" + m.search(a).group(3)
print m.match(a).group()
print m.match(a).group(0)
print (m.match(a).group(0) == m.match(a).group())
print g
在上面的代碼,是基團m.match(a).group()
的整個匹配,是相同m.match(a).group(0)
?如果是這樣,哪個是首選用途?正則表達式匹配組(0)和組()相同嗎?
要麼提出您的問題或不要,請停止對衝的第一句話。 – jonrsharpe