在 re2 中使用正向预测 (?=regex) [英] Using positive-lookahead (?=regex) with re2

查看:29
本文介绍了在 re2 中使用正向预测 (?=regex)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于我对 re2 有点陌生,所以我正在尝试弄清楚如何使用正向预测 (?=regex) 像 JS、C++ 或 Go 中的任何 PCRE 风格.

Since I'm a bit new with re2, I'm trying to figure out how to use positive-lookahead (?=regex) like JS, C++ or any PCRE style in Go.

以下是我正在寻找的一些示例.

Here's some examples of what I'm looking for.

JS:

'foo bar baz'.match(/^[sS]+?(?=baz|$)/);

Python:

re.match('^[sS]+?(?=baz|$)', 'foo bar baz')

  • 注意:两个例子都匹配'foo bar'
  • 非常感谢.

    推荐答案

    根据语法文档,不支持此功能:

    (?=re) 文本匹配前 re(不支持)

    (?=re) before text matching re (NOT SUPPORTED)

    此外,来自 WhyRE2:

    原则上,RE2 不支持已知仅存在回溯解决方案的构造.因此,不支持反向引用和环视断言.

    As a matter of principle, RE2 does not support constructs for which only backtracking solutions are known to exist. Thus, backreferences and look-around assertions are not supported.

    这篇关于在 re2 中使用正向预测 (?=regex)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆