A slightly different answer from sshashank (because the word containing in its answer does not work for me, and in regular expression you should be pedantic - it's all about accuracy.) I am 100% sure that sshashank knows this and only formulated it this way for brevity.
The regular expression matches foo , is not executed (i.e. a negative expression (?! ) As follows:
{{{any number of any characters (ie .* ), then the characters foo }}}
If the browsing failure fails, then the part corresponding to .* Does not contain foo . foo will appear later.
See automatic translation :
NODE EXPLANATION -------------------------------------------------------------------------------- foo 'foo' -------------------------------------------------------------------------------- (?! look ahead to see if there is not: -------------------------------------------------------------------------------- .* any character except \n (0 or more times (matching the most amount possible)) -------------------------------------------------------------------------------- foo 'foo' -------------------------------------------------------------------------------- ) end of look-ahead
The same thing in different words from regex101:
/ Foo (?!. * Foo) /
foo matches the characters foo literally (case sensitive) (?!.*foo) Negative Lookahead - Assert that it is impossible to match the regex below .* matches any character (except newline) Quantifier: Between zero and unlimited times, as many times as possible, giving back as needed [greedy] foo matches the characters foo literally (case sensitive)
What has RegexBuddy to say?
Foo (?!. * Foo)
foo(?!.*foo)
- Matches the character string "foo" literally (case sensitive)
foo - Affirm that it is not possible to combine the regex below starting at this position (negative view)
(?!.*foo)- Matches any character that is not a line break character (line, carriage return, next line, line separator, paragraph separator)
.*- Between zero and unlimited time intervals, as many times as possible, returning as necessary (greedy)
*
- Matches the character string "foo" literally (case sensitive)
foo
zx81
source share