Scripting Guide > Types of Data > Regular Expressions > Escaped Characters in Regular Expressions
发布日期: 09/18/2023

Escaped Characters in Regular Expressions

The backslash in a regular expression precedes a literal character. You also escape certain letters that represent common character classes, such as \w for a word character or \s for a space. The following example matches word characters (alphanumeric and underscores) and spaces.

Regex(
	"Are you there, Alice?, asked Jerry.", // source
	"(here|there).+(\w+).+(said|asked)(\s)(\w+)\." ); // regular expression

"there, Alice?, asked Jerry."

(here|there).+

Matches “there”, a comma, and a space.

(\w+)

Matches “Alice”.

.+

Matches “?, “.

(said|asked)(\s)

Matches “asked” followed by a space. Without the space, the match would end here; “asked” is followed by a space in the source string.

(\w+)\.

Matches “Jerry” and a period.

表 6.10 describes the escaped characters supported in JMP. \C, \G, \X, and \z are not supported.

Table 6.10 Escaped Characters

\\

single backslash

\A

start of a string

\b

word boundary. The zero-length string between \w and \W or \W and \w.

\B

not at a word boundary

\cX

ASCII control character

\d

single digit [0-9]

\D

single character that is NOT a digit [^0-9]

\E

stop processing escaped characters

\l

match a single lowercase letter [a-z]

\L

single character that is not lowercase [^a-z]

\Q

ignore escaped characters until \E is found

\r

carriage return

\s

single whitespace character

\S

single character that is NOT white space

\u

single uppercase character [A-Z]

\U

single character that is not uppercase [^A-Z]

\w

word character [a-zA-Z0-9_]

\W

single character that is NOT a word character [^a-zA-Z0-9_]

\x00-\xFF

hexadecimal character

\x{0000}-\x{FFFF}

Unicode code point

\Z

end of a string before the line break

需要更多信息?有问题?从 JMP 用户社区得到解答 (community.jmp.com).