What is RegExp
RegExp is a pattern used to describe what to retrieve.
Define RegExp
1 var New REGEXP ("mode");
Methods for RegExp objects
RegExp objects have 3 methods: Test (), exec (), compile ()
Test ()
Retrieves the value specified in the string. The return value is TRUE or False
1 var New REGEXP ("E"); 2 document.write (patt.test ("I am a Student"); 3 // return value 4 true
EXEC ()
Retrieves the value specified in the string. The return value is the found value, and null is returned if no match is found.
1 var New REGEXP ("E"); 2 document.write (patt.exec ("I am a student."); 3 //return value 4 E
A second parameter can be set to set the retrieval
G: Global Search
I: Perform a case insensitive match
M: Perform multi-line matching
1 var New REGEXP ("E", "G"); 2 Do {3 result = patt.exec ("I am a student in the university"); 4 document.write (result); 5 while NULL ); 6 // Execution Results 7 Eeenull
Compile ()
Used to change regexp.
That is, you can change the retrieval mode, or you can add or remove a second parameter.
1 var New REGEXP ("E"); 2 document.write (patt.test ("I am a Student"); 3 patt.compile ("B"); 4 document.write (patt.test ("I am a Student"); 5 // Output Results 6 TrueFalse
Summary from: http://www.w3school.com.cn/js/js_obj_regexp.asp
JavaScript Regular Expression (REGEXP)