This topic describes the metacharacters, character classes, and escape characters supported by regular expressions in MaxCompute SQL. For information about the usage and examples of the RLIKE operator, see RLIKE.
Metacharacters
Metacharacter | Description |
| Matches the beginning of a string. |
| Matches the end of a string. |
| Matches any single character. |
| Matches the preceding character or pattern zero or more times. |
| Matches the preceding character or pattern one or more times. |
|
|
| Matches A or B. |
| Matches the sequence |
|
|
| Matches any character listed in the brackets. |
| Matches any character in the range a through d (a, b, c, or d). |
|
|
| POSIX character group syntax. See . |
| Escape character. |
| Back reference, where n is a digit from 1 to 9. |
| Matches any digit (0–9). |
| Matches any non-digit character. |
Examples
For more usage examples, see RLIKE.
General pattern matching
Matching the beginning and end of a string
-- Check whether the string aa123bb starts with a. Returns true. SELECT 'aa123bb' RLIKE '^a';Matching any character
-- Check whether the string cc123bb starts with any character in the range a to d. Returns true. SELECT 'cc123bb' RLIKE '^[a-d]'; -- Check whether the string 12abc34 starts with 12, ends with 34, and contains at least one character in the range a to d in between. Returns true. SELECT '12abc34' RLIKE '^12[a-d]+34$';
Escape character matching
The RLIKE operator uses a backslash (\) as the escape character. Therefore, any backslash (\) that appears in a regular expression pattern must be escaped twice.
Example 1
To match the string
a+b, where+is a special regex character, it must be escaped. In the regex engine, this is expressed asa\+b. Because an additional layer of escaping is required, the expression that matches the string isa\\+b.SELECT 'a+b' RLIKE 'a\\+b'; -- Results: +------+ | _c1 | +------+ | true | +------+Example 2
If the string contains a tab character (TAB), the system stores
\tas a single character when reading it. Therefore, in the regex pattern, it is treated as a regular character.SELECT 'a\tb', 'a\tb' RLIKE 'a\tb'; -- Results: +---------+------+ | _c0 | _c1 | +---------+------+ | a b | true | +---------+------+
Character groups
POSIX character groups
Character group | Description | Equivalent |
| Letters and digits |
|
| Letters |
|
| ASCII characters |
|
| Space and tab |
|
| Control characters |
|
| Digits |
|
| Printable characters except space |
|
| Lowercase letters |
|
|
|
|
| Punctuation |
|
| Whitespace characters |
|
| Uppercase letters |
|
| Hexadecimal digits |
|
MaxCompute does not support \f or \v.
Chinese character groups
Character group | Pattern |
Double-byte characters (e.g., Chinese characters) |
|
Chinese characters |
|
Chinese punctuation | Chinese punctuation marks do not have a unified encoding range. You can search for the Unicode code points of Chinese punctuation marks in a search engine, and then use operators to exclude them one by one. |