问题描述
我需要在双引号之间匹配一个换行符,如下所示:
I need to match a linebreak in-between double quotes, as in:
<p class="calibre1">"This is the first sentence.</p>
<p class="calibre1">And this is the second!"</p>
这将匹配</p> <p class="calibre1">
现在,我使用正则表达式(?<=[^]*)</p>\s*<p[^>]*>(?!)
进行了此操作,但遇到标题中描述的错误:"无效的正则表达式:look-behind需要固定宽度模式"非手动使用.我需要用于电子书管理/编辑程序Calibre的此正则表达式,该程序将Python用于其正则表达式引擎.上面的正则表达式可用于手动搜索书籍,但是当我尝试将正则表达式作为常用选项"(在每次电子书转换时运行)时,都会出现该错误.
Now, I got this working with the regex (?<="[^"]*)</p>\s*<p[^>]*>(?!")
but I get the error described in the title: "Invalid regular expression: look-behind requires fixed-width pattern" when I try to use it non-manually. I need this regex for the eBook management/editing program, Calibre, which uses Python for its regex engine. The regex above works for manually searching a book, but when I try to include the regex as a "common option" (run on each eBook conversion) I get that error.
我不知道在没有可变宽度的情况下如何做到这一点,因为您不知道从左双引号到换行符将持续多长时间.帮助将不胜感激!
I don't see how it's possible to do this without a variable width look-behind, since you can't know how long it will be from the left doublequote to the linebreak. Help would be much appreciated!
推荐答案
Python re
模块,因为大多数语言(.NET除外)都不支持可变长度后向.
Python re
module, as most languages (with the notable exception of .NET), doesn't support variable length lookbehind.
您不能使用捕获组吗?
"[^"]*(</p>\s*<p[^>]*>)
这篇关于Python后置正则表达式问题:无效的正则表达式:后置需要固定宽度模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!