Detailed analysis of the regular test,match,exec of JS

Source: Internet
Author: User

  This article is mainly on the JS regular test,match,exec was introduced, the need for friends can come to the reference, I hope to help you.

Regular expression GI I can not understand the beginning, I found it from the Internet, and now I share it with you. The following are expressions:/pattern/flags (/mode/tag)   constructor function methods are used as follows: New REGEXP ("pattern" [, "Fla GS "] is the new REGEXP (" mode "[," tag "]) Parameter: pattern (mode) represents the literal flags (tokens) of regular expressions If this is specified, flags can be one of the lower denominations: G:global match (full set matching) I:ignore C ASE (ignores case) Gi:both the global match and ignore case (matching all possible values, also ignoring casing) expressions to establish the same regular expression such as:  /AB+C/GI   Regular expression/i,/g,/ig, Difference and meaning of/gi,/m   I (ignore case)/g (all matching characters that appear in Full-text lookup)/m (multiline lookup)/gi (Full-text lookup, ignore case)/ig (full-text lookup, ignore case)   Test,match,exec   Regular expressions are often used in JavaScript, while regular expressions often use the two functions of match and test, and of course exec. Here's a code example to differentiate between them.   Match Example     code as follows: var str = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ"; var regexp =/[a-e]/gi;   var rs = Str.match (regexp);  //rs= Array (' A ', ' B ', ' C ', ' D ', ' e ', ' A ', ' B ', ' C ', ' d ', ' e ');     Test Example   code as follows: var str = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ"; var regexp =/[a-e]/gi;   var rs = regexp.test (str);  //rs = true; Boolean    EXC Example   code is as follows: var str = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ"; var regexp =/[a-e]/gi; var rs; while (rs = regexp.exec (str))!= null) {    document.write (RS);     document.write (Regexp.lastindex) ;     document.write ("<br/>"); }    

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.