When specified, the pattern character
'^' matches at the beginning of the
string and at the beginning of each
line (immediately following each
newline); and the pattern character
'$' matches at the end of the string
and at the end of each line
(immediately preceding each newline).
By default, '^' matches only at the
beginning of the string, and '$' only
at the end of the string and
immediately before the newline (if
any) at the end of the string.
When specified, the pattern character
'^' matches at the beginning
of the string and at the beginning of
each line (immediately following each
newline); and the pattern character
'$' matches at the end of the string
and at the end of each line
(immediately preceding each newline).
By default, '^' matches only at the
beginning of the string, and '$' only
at the end of the string and
immediately before the newline (if
any) at the end of the string.
>>> re.search("^(.*)$^.*$", multiline_string, re.M) # won't match
>>> re.search("^(.*)$\n^.*$", multiline_string, re.M) # will match
<_sre.SRE_Match object at 0xb7f3e5e0>
看看^{} 。在
我引用:
你必须使用re.多行(或者甚至雷多尔如果您更改regex,并且取决于您实际想要匹配/执行的操作)
http://docs.python.org/library/re.html
顺便说一句,你在用-},这是问题的重点。)在
^(.*\|.*)$^.*$
-这不是一个很好的正则表达式!(忽略了一个事实,你有多个$
和{正如其他答案所说,您正在寻找
re.MULTILINE
,但即使这样,您的regex也无法工作。在$
匹配换行符之前的位置,^
匹配行的开头,因此regex中间的$^
永远不会匹配。例如:您需要一些东西来匹配
$
和^
之间的行尾字符。在相关问题 更多 >
编程相关推荐