The notion that regex doesn't support inverse matching is not entirely true. You can mimic this behavior by using negative look-arounds:

^((?!hede).)*$

The regex above will match any string, or line without a line break, not containing the (sub)string 'hede'. As mentioned, this is not something regex is "good" at (or should do), but still, it is possible.

And if you need to match line break chars as well, use the DOT-ALL modifier (the trailing s in the following pattern):

/^((?!hede).)*$/s

or use it inline:

/(?s)^((?!hede).)*$/

(where the /.../ are the regex delimiters, i.e., not part of the pattern)

If the DOT-ALL modifier is not available, you can mimic the same behavior with the character class [\s\S]:

/^((?!hede)[\s\S])*$/

Explanation

A string is just a list of n characters. Before, and after each character, there's an empty string. So a list of n characters will have n+1 empty strings. Consider the string "ABhedeCD":

    ┌──┬───┬──┬───┬──┬───┬──┬───┬──┬───┬──┬───┬──┬───┬──┬───┬──┐
S = │e1│ A │e2│ B │e3│ h │e4│ e │e5│ d │e6│ e │e7│ C │e8│ D │e9│
    └──┴───┴──┴───┴──┴───┴──┴───┴──┴───┴──┴───┴──┴───┴──┴───┴──┘

index    0      1      2      3      4      5      6      7

where the e's are the empty strings. The regex (?!hede). looks ahead to see if there's no substring "hede" to be seen, and if that is the case (so something else is seen), then the . (dot) will match any character except a line break. Look-arounds are also called zero-width-assertions because they don't consume any characters. They only assert/validate something.

So, in my example, every empty string is first validated to see if there's no "hede" up ahead, before a character is consumed by the . (dot). The regex (?!hede). will do that only once, so it is wrapped in a group, and repeated zero or more times: ((?!hede).)*. Finally, the start- and end-of-input are anchored to make sure the entire input is consumed: ^((?!hede).)*$

As you can see, the input "ABhedeCD" will fail because on e3, the regex (?!hede) fails (there is "hede" up ahead!).

不包含字符串abc的正则表达式_笑的自然技术博客-CSDN博客

https://blog.csdn.net/xxd851116/article/details/7576624

2012年5月17日 ... abc]表示不包含a、b、c中任意字符, 我想实现不包含字符串abc应该如何写表达式? 最简洁的写法:\b((?!abc)\w)+\b匹配由字母或数字或下划线或 ...

Regular expression to match a line that doesn't contain a word ...

https://stackoverflow.com/questions/406230/regular-expression-to-match-a-line-that-doesnt-contain-a-word

You can mimic this behavior by using negative look-arounds: ^((?!hede).)*$. The regex above will match any string, or line without a line break, not containing ...

正则表达式里”不包含”及一些特殊查找- 简书

https://www.jianshu.com/p/9fd05dfdde48

背景我经常使用sublime去处理很多文件, 利用强大的正则表达式, 将一些日志以及 excel文本进行格式化为特定 ... 当我要找到不包含某字符串(如test)时, 可以使用

正则表达式匹配不包含某字符串的技巧_JHON_03的博客-CSDN博客

https://blog.csdn.net/JHON_03/article/details/77899563

2017年9月8日 ... 经常我们会遇到想找出不包含某字符串的文本,程序员最容易想到的是在正则 表达式里使用,^(hede)来过滤”hede”字串,但这种写法是错误的。

Match string not containing string - Regex Tester/Debugger

https://www.regextester.com/15

Regular Expression to Given a list of strings (words or other characters), only return the strings that do not match.

利用正则表达式排除特定字符串- 薰衣草的旋律- 博客园

https://www.cnblogs.com/wangqiguo/archive/2012/05/08/2486548.html

2012年5月8日 ... 查找不以baidu开头的字符串baidu.comsina.com.cn 查找不以baidu开头的字符串 正则:^(?!baidu).*$ 匹配结果就是第2行,也就是第1行被排除了 ...

正则表达式字符串"不包含"匹配技巧| 外刊IT评论- 程序员、编程语言 ...

https://www.aqee.net/post/regular-expression-to-match-string-not-containing-a-word.html

经常我们会遇到想找出不包含某字符串的文本,程序员最容易想到的是在正则 表达式里使用, ^(hede) 来过滤”hede”字串,但这种写法是错误的。我们可以这样  ...

正则表达式不包含某字符串怎么办? - 问答- 云+社区- 腾讯云

https://cloud.tencent.com/developer/ask/57182

2018年3月6日 ... 一般来说写一个不包含特定字符串正则表达式是一种痛苦。我们必须为计算模型 执行此操作- 你需要一个易于定义的NFA,然后将其降至正则表达 ...

Regex matching line not containing the string - Super User

https://superuser.com/questions/1279062/regex-matching-line-not-containing-the-string

I'd like to select a lines with does not contain a word SCREEN. I tried the following regex (?<!SCREEN).+ but it seems not to work - selects all the lines. Why doesn' ...

How to write regular expression for string not containing certain ...

https://www.ibm.com/mysupport/s/question/0D50z00006HIL46/how-to-write-regular-expression-for-string-not-containing-certain-substring?language=fi

I need a method to write regular expressions, for negative checking whether a string contains a given substring. I know this might sound difficult, but for example  ...

正则不包含某字符串表达式匹配方法- 365学习- 365建站网

https://www.365jz.com/article/24080

2017年12月24日 ... 经常我们会遇到正则不包含某字符串的文本,^(hede)来过滤hede字串,但这种 写法是错误的。我们可以这样写:[^hede],但这样的正则表达式 ...

正则表达式不包含某字符串-华为云

https://www.huaweicloud.com/theme/430663-1-Z

华为云为你分享正则表达式不包含某字符串相关内容问答等,同时提供内容包含 产品介绍、用户指南、开发指南、最佳实践以及常见问题等相关信息帮助用户快速  ...

Regular expression for the strings without a particular substring ...

https://cs.stackexchange.com/questions/11787/regular-expression-for-the-strings-without-a-particular-substring

How can we design a regular expressions without particular substrings. The goal of this is to create language L which won't contain a particular substring (i.e. ...

Example of language that does not contain substring $11 ...

https://math.stackexchange.com/questions/2362133/example-of-language-that-does-not-contain-substring-11

Jul 18, 2017 ... Therefore, the set of words not containing u as a substring is the complement of L (u). If you want a regular expression for this language, you can ...

Write a regex to match string that does NOT contain a certain pattern ...

https://cs.stackexchange.com/questions/66513/write-a-regex-to-match-string-that-does-not-contain-a-certain-pattern

Nov 26, 2016 ... If a string does not contain 101, then every 10 either terminates the string or is followed by 0. So if r is a regular expression for all strings not ...

5.11. Match Complete Lines That Do Not Contain a Word - Regular ...

https://www.oreilly.com/library/view/regular-expressions-cookbook/9781449327453/ch05s11.html

If you invert the state of these two options, the regular expression will match any complete string that does not contain the word “error.” Caution. Testing a negative ...

Documentation: 9.3: Pattern Matching - PostgreSQL

https://www.postgresql.org/docs/9.3/functions-matching.html

If pattern does not contain percent signs or underscores, then the pattern only ... A string is said to match a regular expression if it is a member of the regular set ...