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.