Example of js Regular Expressions test () and exec (), regular expression exec

Source: Internet
Author: User

Example of js Regular Expressions test () and exec (), regular expression exec

This document describes how to use the js Regular Expressions test () and exec. Share it with you for your reference. The details are as follows:

Copy codeThe Code is as follows:
<Html>
<Head>
<Script type = "text/javascript">
// Regular. test (content), returns true or false
Function t1 (){
Var con = document. getElementsByName ('content') [0]. value; // the content to be searched
Var reg =/hi/; // the content to be matched
Alert (reg. test (con ));
}
// The regular expression .exe c (content) returns the matched content
Function t2 (){
Var con = document. getElementsByName ('content') [0]. value; // the content to be searched
Var reg =/\ bhi \ w +/; // the content to be matched
Alert(reg.exe c (con ));
}
</Script>
</Head>
<Body>
<Textarea rows = "5" cols = "30" name = "content"> </textarea> <br/>
<Button onclick = "t1 ();"> regular expression test </button> <br/>
<Button onclick = "t2 ();"> regular expression test (exec function) </button>
</Body>
</Html>

I hope this article will help you learn regular expressions.

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.