英文:
Regex is match just if a character is not present
问题
I am looking for a regex that finds the match only and only if either the word KO or the word OK is not present within the string (regardless of what is before and after).
我正在寻找一个正则表达式,只有当字符串中不存在单词KO或OK时才匹配(无论前后有什么)。
I tried this:
我尝试过这个:
[^OK|KO]
But it doesn't work.
但它不起作用。
example of what I would like to match:
我想匹配的示例:
- 20032023
example of what I would like NOT to match:
我不想匹配的示例:
- 20032023 KO
- OK 123456 20032023
英文:
I am looking for a regex that finds the match only and only if either the word KO or the word OK is not present within the string (regardless of what is before and after).
I tried this:
[^OK|KO]
But it doesn't work.
example of what I would like to match:
-
20032023
example of what I would like NOT to match:
- 20032023 KO
- OK 123456 20032023
答案1
得分: 0
我认为你在寻找类似这样的内容:(?!.*(OK|KO).*)^.+$
,这里的^.+$
是主要匹配(它匹配整行),而(!?....)
部分则进行否定匹配,因此不会匹配包含OK|KO的文本。
英文:
I think you are looking for something like this (?!.*(OK|KO).*)^.+$
. here ^.+$
is a main match (it matches whole lines), and (!?....)
piece makes the negation, so matches that also contain OK|KO won't be taken
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论