Regular expression GI
I couldn't understand it at the beginning, I saw it after finding it online, and now share it with you
The general item of the expression: /pattern/flags is (/mode/mark)
The method of the constructor function method is as follows:
New RegExp ("Pattern" [, "Flags"] is New Regexp ("Mode" [, "Label"])
parameter:
pattern (mode)
Text that indicates regular expression
Flags (mark)
If this item is specified, Flags can be one of the following values:
G: Global Match (fixed matching)
I: IGNORE CASE
GI: Both Global Match and Ignore Case
The same regular expression is established for expression, such as::
/AB+C/GI
The differences and meanings of/i,/g,/iG,/g,/m in the regular expression
/i (Lifting -down)
/g (Full text Find all the matching characters)
/m (multi -line search)
/gi (Full text search, ignoring a lowercase)
/IG (Full Text Find, ignore a lowercase)
test, match, exec
Two functions are often used in JavaScript, and Match and Test are often used in regular expressions. Of course, there are exec. Here is a code example to distinguish the difference between them.
Match exmple
Copy code code as follows:
var str = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz";
var regexp = /[ae] /gi;
var rs = str.match (regexp);
// rs = array ('a', 'b', 'c', 'd', 'e', 'a', 'b', 'c', 'd', 'e');
Test Example
Copy code code as follows:
var str = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz";
var regexp = /[ae] /gi;
var rs = regexp.test (STR);
// rs = true; BOOLEAN
Exc EXAMPLE
Copy code code as follows:
var str = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz";
var regexp = /[ae] /gi;
var rs;
While ((RS = RegExp.exec (STR))! = NULL)
{{
document.write (RS);
document.write (regexp.lastindex);
document.write ("<br />");
}