This article mainly introduces the regular expression matching techniques that do not contain certain strings, and details the reasons for doing so, if you want to find the text that does not contain a certain string, you can refer to it. the programmer can use it in a regular expression, ^ (hede) to filter the "hede" string, but this method is incorrect. We can write it like this: [^ hede], but such a regular expression completely means that the string cannot contain 'H', 'e ', 'D' contains three characters. So what regular expressions can filter out information that does not contain the complete "hello" string?
In fact, regular expressions do not support reverse matching. Just like this problem, we can use a negative lookup to simulate reverse matching to solve our problem:
^ ((?! Hede).) * $
The above expression can filter out information that does not contain the 'hede' string. As I mentioned above, this method is not a regular expression that is "good at", but it can be used in this way.
Explanation
A string consists of n characters. There is an empty character before and after each character. In this way, a string consisting of n characters has n + 1 null string. Let's take a look at the "ABhedeCD" string:
This question is to match words that do not include abba, such as abba and anallagmatic.
Regular expression code:
^ (?!. * (.) (.) \ 2 \ 1)
Then, we can solve the prime problem by using non-matching. this question matches the string of several x numbers. let's first look at the regular expression.
^ (?! (Xx +) \ 1 + $)
(Xx +) is to match two or more x, (xx +) \ 1 + is to match two or more strings, so (xx +) \ 1 + indicates the strings with non-prime numbers, so the prime number is to remove these non-prime strings, that is, the above regular expression.
For more articles about regular expression matching techniques that do not contain certain strings, refer to the PHP Chinese website!