How can I simulate a negative lookup in a regular expression

时间:2016-02-03 03:23:29

标签: regex regex-lookarounds alteryx

I have the following regular expression that includes a negative look ahead. Unfortunately the tool that I'm using does not support regular expressions. So I'm wondering if its possible to achieve negative look ahead behaviour without actually using one.

Here is my regular expression:

(?<![ABCDEQ]|\[|\]|\w\w\d)(\d+["+-]?)(?!BE|AQ|N)(?:.*)

Here it is working with sample data on Regex101.com:

see expression on regex101.com

I'm using a tool called Alteryx. The documentation indicates that it uses Perl, however, for whatever reason the look ahead does not work.

1 个答案:

答案 0 :(得分:3)

Alteryx似乎使用Boost库进行正则表达式支持,而Boost documentation表示lookbehind表达式必须具有固定长度。它比PHP(PCRE)更具限制性,它允许您在后视中使用交替,只要每个分支是固定长度的。但这很容易解决:只使用多个lookbehinds:

(?<![ABCDEQ])(?<!\[)(?<!\])(?<!\w\w\d)(\d+["+-]?)(?!BE|AQ|N)(?:.*)

这个正则表达式适用于我在Boost驱动的正则表达式测试程序中,在那里你没有。我会通过在字符集中放置方括号来压缩它:

(?<![][ABCDEQ])(?<!\w\w\d)(\d+["+-]?)(?!BE|AQ|N)(?:.*)

右括号在列出的第一个字符时被视为文字,左括号从不特殊(尽管其他一些风格有不同的规则)。

这里有更新的demo

相关问题