regex - 正则表达式前瞻量词
问题描述
我想匹配字符串b
前面的最后一个。aa
ababaaabaab
我的正则表达式:(?<=a{2})b
但它与前面的第三个 匹配。b
aaa
我是初学者。
解决方案
利用
(?<=(?<!a)a{2})b
见证明。
解释
--------------------------------------------------------------------------------
(?<= 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'
推荐阅读
- django - 为要在 Docker 容器中使用的 SSL 证书生成私钥
- python - 由于 MACOSX_DEPLOYMENT_TARGET,Big Sur clang “无效版本”错误
- javascript - 单击应显示其余文本
- python - 我无法弄清楚为什么我的 python 代码没有以英里为单位返回答案
- python - Python Vector Fields
- python - BeautifulSoup is returing none
- java - Java 15 的密封类功能中的最终类和非密封类有什么区别?
- python - 将 python 模块导入 colab - ModuleNotFoundError
- python - 如何删除列表中的重复数字(Python)?
- python - 函数和随机化问题 - 初学者 python