


Detailed analysis of regular test, match, and exec of js_javascript skills
May 16, 2016 pm 05:01 PMRegular 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 str = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
var regexp = /[A-E]/gi;
var rs = str.match(regexp);
//rs= Array('A', 'B', 'C', 'D', 'E', 'a', 'b', 'c', 'd', 'e');
Test Example
var str = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
var regexp = /[A-E]/gi;
var rs = regexp.test(str);
// rs = true; boolean
Exc Example
var str = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
var regexp = /[A-E]/gi;
var rs;
while ((rs = regexp.exec(str)) != null)
{
document.write(rs);
document.write(regexp.lastIndex);
document.write("<br />");
}

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

How to use JS and Baidu Maps to implement map pan function

Recommended: Excellent JS open source face detection and recognition project

Essential tools for stock analysis: Learn the steps to draw candle charts with PHP and JS

PHP and JS Development Tips: Master the Method of Drawing Stock Candle Charts

How to create a stock candlestick chart using PHP and JS

How to match multiple words or strings using Golang regular expression?

How to use JS and Baidu Maps to implement map polygon drawing function

How to use JS and Baidu Map to implement map click event processing function
