I also talk about JavaScript regular matching

Source: Internet
Author: User

One, JavaScript regular global match G caution with the test () method

Here's an example:

var  a =/^[a-z]+/gi;a.test (' bb123 ');//truea.lastindex;//0a.test (' bb123 ')    //Falsea.lastindex;//2a.test (' Bb123 ');  True

Why is it that this is the right thing to do and the wrong situation? This is what should be affected by the global match G effect. Hey

Because the test method is called multiple times when the match starts from the last match, it can cause an error problem that cannot be matched. (even if the content conforms to the requirements of a regular expression, the test () method tests the output false instead of true. )

I'll finish it later. Http://www.coding123.net/article/20130108/javascript-regex-global-matcth-care-of-test-method.aspx

http://tool.chinaz.com/regex/

I also talk about JavaScript regular matching

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.