gpt4 book ai didi

正则表达式前瞻量词

转载 作者:行者123 更新时间:2023-12-04 14:54:23 26 4
gpt4 key购买 nike

我要匹配最后b前面是 aa来自字符串 ababaaabaab .

我的正则表达式:(?<=a{2})b

但它匹配第三个 b前面是 aaa .

我是初学者。

最佳答案

使用

(?<=(?<!a)a{2})b

参见 proof .

解释

--------------------------------------------------------------------------------
(?<= look behind to see if there is:
--------------------------------------------------------------------------------
(?<! look behind to see if there is not:
--------------------------------------------------------------------------------
a 'a'
--------------------------------------------------------------------------------
) end of look-behind
--------------------------------------------------------------------------------
a{2} 'a' (2 times)
--------------------------------------------------------------------------------
) end of look-behind
--------------------------------------------------------------------------------
b 'b'

关于正则表达式前瞻量词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68386021/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com