正则表达式否定匹配查询 [英] Regex negative match query

查看:39
本文介绍了正则表达式否定匹配查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个正则表达式问题,我试图忽略数字41",我希望 4、1、14 等全部匹配.

I've got a regex issue, I'm trying to ignore just the number '41', I want 4, 1, 14 etc to all match.

我有这个 [^\b41\b] 这实际上是我想要的,但这也忽略了值 1 和 4 的所有单次迭代.

I've got this [^\b41\b] which is effectively what I want but this also ignores all single iterations of the values 1 and 4.

例如,这匹配41",但我希望它不匹配:\b41\b

As an example, this matches "41", but I want it to NOT match: \b41\b

推荐答案

尝试类似:

\b(?!41\b)(\d+)

(?!...) 结构是一个 否定向前看,所以这意味着:找到一个不是后跟41"的词边界,并在它后面捕获一个数字序列.

The (?!...) construct is a negative lookahead so this means: find a word boundary that is not followed by "41" and capture a sequence of digits after it.

这篇关于正则表达式否定匹配查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆