If zero or more characters at the beginning of string match the regular expression pattern, return a corresponding MatchObject instance. Return None if the string does not match the pattern; note that this is different from a zero-length match.
在这种情况下,应该使用search:
Scan through string looking for the first location where the regular expression pattern produces a match, and return a corresponding MatchObject instance. Return None if no position in the string matches the pattern; note that this is different from finding a zero-length match at some point in the string.
请尝试以下操作:
你转义下划线字符是对的! 请注意,您只能对字符串的开头使用match,这在文档(https://docs.python.org/2/library/re.html)中也很清楚:
在这种情况下,应该使用
search
:如果您要查找的模式不在搜索字符串的开头,请使用
re.search
,而不是re.match
。您不需要转义
_
,甚至不需要使用原始字符串。相关问题 更多 >
编程相关推荐