s.regex()

描述:

用正则表达式匹配字符串。

语法:

s.regex(rs,rpls)

备注:

用正则表达式rs匹配字符串s,并将s里第一个匹配的字符替换成字符串rpls返回替换后的字符串。

参数rpls缺省则返回可匹配的字符串组成的序列,不匹配时返回null

参数:

s

字符串。

rs

正则表达式。

rpls

字符串。

选项:

@c

大小写不敏感。

@u

使用unicode

@a

替换所有匹配的字符。

@w

整个字符串匹配。

返回值:

序列/字符串

示例:

 

A

 

1

4,23,a,test

 

2

a,D

 

3

小明,中国

 

4

=A1.regex("(\\d),([0-9]*),([a-z]),([a-z]*)")

5

=A2.regex@c("([a-z]),([a-z])")

使用@c选项,不区分大小写

6

=A2.regex("([a-z]),([a-z])")

不匹配返回null

7

=A3.regex@u("(\\u5c0f\\u660e),(\\u4e2d\\u56fd)")

使用unicode匹配:

 

8

=A1.regex("([0-9])","hello")

hello,23,a,test

9

=A1.regex@a("([0-9])","hello")

hello,hellohello,a,test

10

="123abc".regex("[0-9]a")

123abc

11

="123abc".regex@w("[0-9]a")

使用@w选项,整个字符串匹配,结果返回null

相关概念:

A.regex()

cs.regex()