【发布时间】:2016-05-28 01:44:20
【问题描述】:
我有一个匹配 P.O. 的正则表达式。给定地址上的 BOX - /p\.? *o\.? *box/i。但最近我的要求更改为 不 与 P.O. 匹配。盒子。换句话说,地址在 P.O. 时有效。没有找到 BOX。我试图否定该模式,以便它匹配一个没有 P.O. 的地址。 BOX 通过使用negative lookahead,这是我目前想出的:/.*(?!p\.? *o\.? *box).*/i,但它现在不起作用:https://regex101.com/r/oN1jZ8/1
例如,我尝试匹配以下内容:
- 这是一个有效的地址
但不是以下:
- 这是一个无效地址,因为它包含一个 P.O.盒子
- 邮箱显示无效
我知道一些类似的帖子,例如:
- How to negate the whole regex?
- Regular Expressions and negating a whole character group
- Regex to negate the whole word?
negative lookaround 几乎是解决方案。
【问题讨论】:
标签: regex regex-negation negative-lookahead