Js Abba reverse lookup regular matching instance and jsabba forward-looking instance

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.