3

我有一个正则表达式,它匹配不以“DEF”开头的单词。

现在我想将其修改为以下三种情况:

  1. 不以“DEF”结尾
  2. 不包含“DEF”
  3. 不等于“DEF”

我应该如何修改字符串模式?

Regex pattern Match word which does NOT start with word "DEF":  ^(?!DEF).*$
match word :  ADEFCCC
Does Not Match :   DEFXXX
4

1 回答 1

9
Does not end with DEF:   ^.*(?<!DEF)$
Does not contain DEF:    ^((?!DEF).)*$
Does not equal DEF:      ^(?!DEF$).*$
于 2013-10-05T10:29:01.703 回答