import repattern = re.compile("^([A-Z][0-9]+)+$")pattern.match(string)编辑:如注释中所述,
match仅检查字符串开头的匹配项,而
re.search()匹配字符串中任何位置的模式。(另请参见:https : //docs.python.org/library/re.html#search-vs-
match)

import repattern = re.compile("^([A-Z][0-9]+)+$")pattern.match(string)编辑:如注释中所述,
match仅检查字符串开头的匹配项,而
re.search()匹配字符串中任何位置的模式。(另请参见:https : //docs.python.org/library/re.html#search-vs-