[英]How to find string between '\begin{minipage}' and '\end{minipage}' by python re?
I have tried the following code: 我尝试了以下代码:
strReFindString = u"\\begin{minipage}"+"(.*?)"
strReFindString += u"\\end{minipage}"
lst = re.findall(strReFindString, strBuffer, re.DOTALL)
But it always returns empty list. 但是它总是返回空列表。
How can I do? 我能怎么做? Thanks all. 谢谢大家
As @BrenBarn said, u"\\\\b"
parses as \\b
; 正如@BrenBarn所说, u"\\\\b"
解析为\\b
; and \\b
is not a valid regexp escape, so findall
treats it as b
(literal b). \\b
不是有效的正则表达式转义findall
,因此findall
将其视为b
(字面b)。 u"\\\\\\\\b"
is \\\\b
, which regexp understands as \\b
(literal backslash, literal b). u"\\\\\\\\b"
是\\\\b
,正则表达式理解为\\b
(字面反斜杠,字面b)。 You can prevent escape-parsing in the string using raw strings, ur"\\\\b"
is equal to u"\\\\\\\\b"
: 您可以使用原始字符串来防止对字符串进行转义分析, ur"\\\\b"
等于u"\\\\\\\\b"
:
ur"\\b" == u"\\\\b"
# => True
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.