14.4. Regular expression-modifier (tag)

发布时间 : 2025-10-25 13:33:21 UTC      

Page Views: 10 views

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:

image0

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:

image1

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.

image2

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。

image3

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 

尝试一下 »

《地理信息系统原理、技术与方法》  97

最近几年来,地理信息系统无论是在理论上还是应用上都处在一个飞速发展的阶段。 GIS被应用于多个领域的建模和决策支持,如城市管理、区划、环境整治等等,地理信息成为信息时代重要的组成部分之一; “数字地球”概念的提出,更进一步推动了作为其技术支撑的GIS的发展。 与此同时,一些学者致力于相关的理论研究,如空间感知、空间数据误差、空间关系的形式化等等。 这恰好说明了地理信息系统作为应用技术和学科的两个方面,并且这两个方面构成了相互促进的发展过程。