对re2使用正向前瞻(?= regex) [英] Using positive-lookahead (?=regex) with re2

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

问题描述

由于我对 re2 有点新,所以我试图弄清楚如何使用正面预览<$在 Go 中使用JS,C ++或任何PCRE风格的c $ c>(?= regex) a>。



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



JS:
$ b

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

Python:

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




  • 注意:两个例子都匹配'foo bar'



非常感谢。

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


(?= re)(不支持)


另外,从 WhyRE2


原则上,RE2不会支持仅存在回溯解决方案的构造。因此,不支持反向引用和环视声明。



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(/^[\s\S]+?(?=baz|$)/);

Python:

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

  • Note: both examples match 'foo bar '

Thanks a lot.

解决方案

According to the Syntax Documentation, this feature isn't supported:

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

Also, from WhyRE2:

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天全站免登陆