Regular expressions use the backslash character ('') to indicate special forms or to allow special characters to be used without invoking their special meaning. This collides with Python’s usage of the same character for the same purpose in string literals; for example, to match a literal backslash, one might have to write '\' as the pattern string, because the regular expression must be , and each backslash must be expressed as inside a regular Python string literal.
其实也没看懂你到底要匹配哪种模式,不过你的问题上面的应该可以解决。
建议用raw string。
这个规则在
compile
之后确实就是那么当然可以匹配目标字符串
ab*cd
中的ab*c
不想匹配到就加个 r。