s. regex()

Description:

Match a string with the regular expression.

Syntax:

s.regex(rs,rpls)

Note:

The function matches string s with the regular expression rs, replaces the first matched character with string rpls, and returns the string after replacement.

 

It returns a sequence consisting of matching strings when parameter rpls is absent, and null when the matching fails.

Parameter:

s

A string

rs

Regular expression

rpls

A string

Option:

@c

Case insensitive

@u

Use Unicode to match

@a

Replace all matching characters

@w

Find whether the regular expression matches with the whole string

Return value:

Sequence or string

Example:

 

A

 

1

4,23,a,test

 

2

a,D

 

3

W,F

 

4

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

5

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

With @c option, it is case insensitive.

6

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

Return null because they don’t match.

7

=A3.regex@u("(\\u0057),(\\u0046)")

[W,F]; Use unicode to match.

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")

Use @w option to find whether the whole string matches and return null.

Related function:

A.regex()

cs.regex()