Exec: Regular Expression is performed on the string, and the matching result is returned. array [0] is the original string, and array [I] is the position that matches the entire string to be searched.
Test: test whether a string contains a matching result. If the string contains a matching result, true is returned. If the string does not contain a matching result, false is returned.
Match (pattern): regular match is performed based on pattern. If it matches, the matching result is returned. If it does not match, null is returned.
Search (pattern): regular match is performed based on pattern. If a result is matched, the number of indexes is returned; otherwise,-1 is returned.
Replace (pattern, replacement): Perform regular match based on pattern and replace the matching result with replacement.
Split (pattern): Regular segmentation based on pattern, returns a split Array
Instance:
Copy codeThe Code is as follows: function checkForm (){
Var u = document. form_name.check.value;
Var s =/^ [-a-zA-Z0-9 _] + (\. [-a-zA-Z0-9 _] +) * @ [-a-zA-Z0-9 _] + (\. [-a-zA-Z0-9 _] +) * $ /;
Var a = s.exe c (u );
Var a = s. test (u );
Var a = u. match (s );
Var a = u. search (s );
Alert ();
}
Replace
The simplest measure is the ability to replace simple characters. The sample code is as follows:Copy codeThe Code is as follows: var u = "javascript is a good script language ";
// Here I want to replace letter a with Letter
Var s =/a/g;
Var a = u. replace (s, "");
</Script>
SplitCopy codeThe Code is as follows: <script type = "text/javascript">
Var str = "How are you doing today? "
Document. write (str. split ("") + "<br/> ")
Document. write (str. split ("") + "<br/> ")
Document. write (str. split ("", 3 ))
</Script>
Output result:
How, are, you, doing, today?
H, o, w, a, r, e, y, o, u, d, o, I, n, g, t, o, d,, y ,?
How, are, you