Tags are also called modifiers, and the tags of regular expressions are used to specify additional matching strategies.
The tag is not written in the regular expression, but outside the expression in the following format:
/pattern/flags
The following table lists the modifiers commonly used in regular expressions:
Modifier | Meaning | Description |
|---|---|---|
I | Ignore-case insensitive | Set the match to case-insensitive and search case-insensitive: there is no difference between An and a. |
G | Global-Global matching | Find all matches. |
M | Multi line-multiline matching | Make the boundary character? ^? And? $? Match the beginning and end of each line, keeping in mind that it is multiple lines, not the beginning and end of the entire string. |
S | 特殊字符圆点?.?中包含换行符?n | Dots by default?? Is it a match divided by newline characters?n? Any character other than, plus? s? After the modifier,? Contains a newline charactern. |
14.4.1. G modifier ¶
The g modifier finds all matches in the string:

14.4.2. Example ¶
Look for “runoob” in the string:
varstr="Google runoob taobao
runoob";varn1=str.match(/runoob/);//查找第一次匹配项varn2=str.match(/runoob/g);//查找所有匹配项
14.4.3. I modifier ¶
The I modifier is case-insensitive. An example is as follows:

14.4.4. Example ¶
Look for “runoob” in the string:
varstr="Google runoob taobao
RUNoob";varn1=str.match(/runoob/g);//区分大小写varn2=str.match(/runoob/gi);//不区分大小写
14.4.5. M modifier ¶
The m modifier makes ^ and $match the beginning and end of each line in a paragraph of text.
G matches only the first line, and multiple lines are implemented after adding m.

Line wrapping is used in the following instance string:
14.4.6. Example ¶
Look for “runoob” in the string:
varstr="runoobgoogle\\ntaobao\\nrunoobweibo";varn1=str.match(/^runoob/g);//匹配一个varn2=str.match(/^runoob/gm);//多行匹配
14.4.7. S modifier ¶
默认情况下的圆点 . 是 匹配除换行符 \n 之外的任何字符,加上 s 之后, . 中包含换行符 \n。

An example of the s modifier is as follows:
14.4.8. Example ¶
Look in the string:
varstr="google\\nrunoob\\ntaobao";varn1=str.match(/google./);//没有使用
s,无法匹配\nvarn2=str.match(/runoob./s);//使用 s,匹配\n