正则表达式*不*匹配任何字符 [英] Regex to *not* match any characters
问题描述
我知道这是一个很奇怪的目标,但是为了快速修复我们的一个系统,我们确实需要不过滤任何输入并让损坏进入系统.
I know it is quite some weird goal here but for a quick and dirty fix for one of our system we do need to not filter any input and let the corruption go into the system.
我当前的正则表达式是\^.*
"
My current regex for this is "\^.*
"
问题在于它没有按计划匹配字符......但是对于一个匹配它确实有效.使它不起作用的字符串是 ^@jj (基本上任何有 ^ ... 的东西).
The problem with that is that it does not match characters as planned ... but for one match it does work. The string that make it not work is ^@jj (basically anything that has ^ ... ).
现在不匹配任何字符的最佳方法是什么?我正在考虑删除 \
,但只有这样做才会将not"转换为start with"...
What would be the best way to not match any characters now ? I was thinking of removing the \
but only doing this will transform the "not" into a "start with" ...
推荐答案
^
字符并不意味着不是",除了在字符类中 ([]
).如果你不想匹配任何东西,你可以使用匹配任何东西的否定前瞻:(?!.*)
.
The ^
character doesn't mean "not" except inside a character class ([]
). If you want to not match anything, you could use a negative lookahead that matches anything: (?!.*)
.
这篇关于正则表达式*不*匹配任何字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!