JavaScript uses regexp for regular-match methods _javascript techniques

Source: Internet
Author: User

The examples in this article describe the way JavaScript uses regexp to make regular matches. Share to everyone for your reference. The implementation method is as follows:

<script type= "Text/javascript" > var matchedtimes = 0;
  Match one D followed by one or more B's followed by one D//remember matched B ' s and the following D//ignore case
  Myre = new RegExp ("D (b +) (d)", "IG");
  Equivalent to Myreg =/d (b +) (d)/ig; MyArray = Myre.exec ("Ecdbdsdbbdz");
  Ecdbbdbsdbbdz console.log ("Regular Expression String:" + myre.source);
  Console.log ("is global?" + Myre.global);
  Console.log ("Ignore case?" + myre.ignorecase);
  Console.log ("is Mulitiline?" + myre.multiline);
  Console.log ("------------------------------------------------");
  Loginfo (myarray, Myre);
  MyArray = Myre.exec ("Ecdbdsdbbdz");
  Loginfo (myarray, Myre);
    function Loginfo (myarray, Myre) {matchedtimes++;
    Console.log ("This are" + Matchedtimes + "Times match");
    Console.log ("Original String:" + myarray.input);
    Console.log ("Match result Array: [" + MyArray + "]");
    Console.log ("The 0-based index of the match in the string:" + Myarray.index); Console.loG ("The Last matched characters:" + myarray[0]);
    Console.log ("The parenthesized substring matches [1]:" + myarray[1]);
    Console.log ("The parenthesized substring matches [2]:" + myarray[2]);
    Console.log ("The index at which to start the next match:" + myre.lastindex);
  Console.log ("-----------------------------------------------");
  } myRe2 =/^\w+ (\d*) $/ig console.log ("myRe2:" + myre2.source);
  Console.log ("MyRe2 matches ABC1?" + Myre2.test ("ABC1")); Plus this line run to see the result, because it is global match, so lastindex will change,//So the myre2.test of the Back ("ABC") is of course false Console.log ("MyRe2 matches ABC?" + myre2.t
EST ("abc"));

 </script>

The

wants this article to help you with your JavaScript programming.

Related Article

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.