比赛结束后的负面前瞻

问题描述 投票:1回答:1

我正在使用此正则表达式来检查以下文本块。

((?<=(over the)).*)?(ask.*question[s]?| answer(ing)?.*question[s]?)(?!(business))

但是我想排除这个块,因为它里面有business,所以我把它修改为包括一个负向前瞻(?!(business))

它应该排除这个块;

我只想问你几个问题,为你推荐最好的选择。你有什么样的生意?

它应该包括这个块;

我只想问你几个问题,为你推荐最好的选择。

但负面的前瞻似乎不起作用?

regex regex-lookarounds
1个回答
1
投票

而不是(?!(business))你可以使用(?!.*business),因为子串business不是在比赛后,但在零或更多其他字符之后。

使用

((?<=over the).*)?(ask.*questions?| answer(?:ing)?.*questions?)(?!.*business)
                                                               ^^^^^^^^^^^^^^

regex demo

© www.soinside.com 2019 - 2024. All rights reserved.