Home >Web Front-end >JS Tutorial >Detailed analysis of regular test, match, and exec of js_javascript skills
Regular expression gi
I couldn’t understand it at first. I found it on the Internet and saw it. Now I share it with you
The common term of the current expression: /pattern/flags i.e. (/pattern/mark)
The constructor function method is used as follows:
new RegExp("pattern"[, "flags"]) i.e. new RegExp("pattern"[,"flag"])
Parameters:
pattern(pattern)
Text representing the regular expression
flags(mark)
if When specifying this item, flags can be one of the following values:
g: global match (complete match)
i: ignore case (ignore case)
gi: both global match and ignore case (match all Possible values, also ignoring case)
expression creates the same regular expression. For example:
/ab c/gi
The difference and meaning of /i,/g,/ig,/gi,/m in regular expressions
/i (ignore case)
/g (Full-text search for all matching characters)
/m (Multi-line search)
/gi (Full-text search, ignore case)
/ig(Full text search, ignore case)
test,match,exec
Regular expressions are often used in JavaScript, and the two functions Match and Test are often used in regular expressions, and of course Exec. Here are code examples to distinguish the differences between them.
Match Example
var rs = str.match(regexp);
//rs= Array('A', 'B', 'C', 'D', 'E', 'a', 'b', 'c', 'd', 'e');
var rs = regexp.test(str);
// rs = true; boolean