【问题标题】:Negative lookbehind does not work with multiple alternatives in FileLocatorPro regex负后视不适用于 FileLocatorPro 正则表达式中的多种替代方法
【发布时间】:2017-11-28 07:54:23
【问题描述】:
(?<!ing|how|out)\sto\b

我在 FileLocatorPro 中使用的表达式是可以的,但是我在里面添加了一些单词后,比如

  (?<!ing|how|out|wants)\sto\b

出错了。使用“|”有什么限制吗?

【问题讨论】:

  • 表示表达式对正则表达式类型无效。报告的错误:正则表达式中遇到无效的后向断言。@ Wiktor Stribiżew
  • 请参阅下面的解决方案和说明。如果对您有用,请勾选左侧的灰色勾号标记为已接受

标签: regex boost


【解决方案1】:

用于 Perl 兼容选项的 正则表达式 风格是 Boost,请参阅 the FileLocatorPro docs

与 Perl 兼容的正则表达式语法基于 Boost 正则表达式引擎,不仅包括“经典”正则表达式引擎的功能,还包括此处详述的其他 Perl 样式表达式增强功能:http://www.boost.org/doc/libs/release/libs/regex

Boost 文档说(?&lt;!pattern) consumes zero characters, only if pattern could not be matched against the characters preceding the current position (pattern must be of fixed length).

这意味着,lookbehind 中的所有替代项必须具有相同的长度。

解决方法是用相同长度的替代项链接后向:

(?<!ing|how|out)(?<!wants)\sto\b

请参阅regex demo(使用 Python 选项,因为 Python 具有相同的后向长度限制)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-12-18
    • 2023-03-13
    • 1970-01-01
    • 1970-01-01
    • 2012-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-21
    相关资源
    最近更新 更多