regex 不匹配三个结尾的正则表达式[重复]

brc7rcf0  于 7个月前  发布在  其他
关注(0)|答案(1)|浏览(75)

此问题在此处已有答案

Regexp to fit all string NOT ending with a LIST of known suffixes (not characters, but words)(2个答案)
26天前关闭
如何编写一个Java正则表达式来匹配不以abcdef,ot ghi这三种结尾中的任何一种结尾的行?
例如,以下情况应如下所示工作:

1234abc     -- not valid  (ends with 'abc')
09mno       -- valid
ef          -- valid
def         -- not valid (ends with 'def')
hello       -- valid
helloghi    -- not valid (ends with 'ghi')
longertext  -- valid

字符串

s6fujrry

s6fujrry1#

我在regex101.com上玩了一下,得出了这个结论:

^(?!(.*(abc|def|ghi)$))

字符串

编辑25.10.2023在末尾添加了.+$,以不匹配空字符串

^(?!(.*(abc|def|ghi)$)).+$

相关问题