Js Abba reverse lookup regular matching instance and jsabba forward-looking instance
Core code:
<Script> var s1 = 'acritan '; var s2 = 'bassarisk'; var s3 = 'commotive '; // find the word var r =/^ (?!. *? (.) (.) \ 2 \ 1)/I; alert (r. test (s1); // truealert (r. test (s2); // falsealert (r. test (s3); // false </script>
Assertion with Zero Width (?! Exp)
Anti-Predicate
What is anti-Predicate (?! Exp
) The matching is not followed by exp.
Php instance:
I want to explain the role of this regular expression through examples.
$ Str = "abcgwcab"; $ parent = '/bc (?! Ww) gw/'; $ str = preg_match ($ parent, $ str, $ match); var_dump ($ str); var_dump ($ match);/** output: int 1 array (size = 1) 0 => string 'bcgw '(length = 4 )*/
Resolution: first judge whether the string contains bc, then judge whether it is followed by ww, and finally match gw. We can see that after reverse assertions, other matching conditions can be added.
.*?
This. * matches any length of non-null characters ,? That is, the non-Greedy mode matches the least characters, such as a character.