Javascript Regular Expression exercises

Source: Internet
Author: User

<MCE: Script Type = "text/JavaScript"> <! -- <Br/> function f () {<br/> // var Reg = new Regexp ("cat "); <br/> // Example 1 <br/> // var Reg =/^ The/; // start with <br/> // var Reg =/Ere $ /; // end <br/> // var Reg =/her/; // contains <br/> // var S = "there "; <br/> // var r = S. match (REG); <br/> // If (R! = NULL) Alert ("Match successful"); <br/> // Example 2 <br/> // var Reg =/Th */; // 0 or more h after T <br/> // var Reg =/TH + /; // T plus one or more H <br/> // var Reg =/th? // 0 or 1 h after T <br/> // var Reg =/t? E + $/; // starts with 0 or 1, and ends with one or more E. <br/> // var S = "thered "; <br/> // Example 3 <br/> // var Reg =/Th {1 }/; // T has two H <br/> // var Reg =/Th {1 ,}/; // one or more h after T <br/> // var Reg =/Th {3, 5} e /; // 3 to 5 h after T <br/> // var S = "thhhered"; <br/> // var Reg =/Th (ERE) {1 ,} d/; // one or more ere <br/> // var Reg =/^ (Hi | The) [A-Z] * Ed $ /; // hi or the beginning, any letter in the middle, ending with Ed <br/> // var S = "thereered"; <br/> // var Reg =/gv. [0-9] //. represents any character <br/> // var S = "gv211"; <br/> // var re G =/[a-d]/; // lowercase between A and D <br/> // var S = ""; <br/> var Reg =/^ [A-Za-Z] $/; // any letter, one. <Br/> var S = "ad"; <br/> var r = S. Match (REG); <br/> If (R! = NULL) Alert ("Match successful"); <br/>}< br/> function F1 () {// practical example, determine the date format <br/> var Reg =/^ ([0-9] +)-([0-9] {1, 2 }) -([0-9] {1, 2}) ([0-9] {1, 2}) :( [0-9] {1, 2 }) :( [0-9] {}) $/; <br/> var r = "12:12:33 ". match (REG); <br/> If (R! = NULL) Alert ("OK"); <br/>}< br/> document. onclick = F1; </P> <p> // --> </MCE: SCRIPT>

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.