Regex Features#
This page specifies which regular expression (regex) features are currently supported by libcudf strings column APIs that accept regex patterns:
cudf::strings::contains_re()
cudf::strings::matches_re()
cudf::strings::count_re()
cudf::strings::extract()
cudf::strings::extract_all_record()
cudf::strings::findall()
cudf::strings::replace_re()
cudf::strings::replace_with_backrefs()
cudf::strings::split_re()
cudf::strings::split_record_re()
The details are based on features documented at https://www.regular-expressions.info/reference.html
Note: The alternation character is the pipe character |
and not the character included in the tables on this page. There is an issue including the pipe character inside the table markdown that is rendered by doxygen.
Invalid regex patterns will result in undefined behavior. This includes but is not limited to the following:
Unescaped special characters (listed in the third row of the Characters table below) when they are intended to match as literals.
Unmatched paired special characters like
()
,[]
, and{}
.Empty groups, classes, or quantifiers. That is,
()
and[]
without an enclosing expression and{}
without a valid integer.Incomplete ranges in character classes like
[-z]
,[a-]
, and[-]
.Unqualified quantifiers. That is, a quantifier with no preceding item to match like
*a
,a⎮?
,(+)
,{2}a
, etc.
Features Supported#
Characters#
Feature |
Syntax |
Description |
Example |
---|---|---|---|
Literal character |
Any character except |
All characters except the listed special characters match a single instance of themselves |
|
Literal curly braces |
|
|
|
Backslash escapes a metacharacter |
|
A backslash escapes special characters to suppress their special meaning |
|
Hexadecimal escape |
|
Matches the character at the specified position in the ASCII table |
|
Character escape |
|
Match an line-feed (LF) character, carriage return (CR) character and a tab character respectively |
|
Character escape |
|
Match the “alert” or “bell” control character (ASCII 0x07) |
|
Character escape |
|
Match the form-feed control character (ASCII 0x0C) |
|
NULL escape |
|
Match the NULL character |
|
Octal escape |
|
Matches the character at the specified position in the ASCII table |
|
Basic Features#
Feature |
Syntax |
Description |
Example |
---|---|---|---|
Dot |
. (dot) |
Matches any single character except line break characters. Optionally match line break characters. The behavior of the dot when encountering a |
. matches x or (almost) any other character |
Alternation |
|
Causes the regex engine to match either the part on the left side, or the part on the right side. Can be strung together into a series of alternations. |
|
Character Classes#
Feature |
Syntax |
Description |
Example |
---|---|---|---|
Character class |
|
|
|
Literal character |
Any character except |
All characters except the listed special characters are literal characters that add themselves to the character class. |
|
Backslash escapes a metacharacter |
|
A backslash escapes special characters to suppress their special meaning. |
|
Range |
|
Adds a range of characters to the character class. If ‘ |
|
Negated character class |
|
Negates the character class, causing it to match a single character not listed in the character class. |
|
Literal opening bracket |
|
An opening square bracket is a literal character that adds an opening square bracket to the character class. |
|
Character escape |
|
Add an LF character, a CR character, or a tab character to the character class, respectively. |
|
Character escape |
|
Add the “alert” or “bell” control character (ASCII 0x07) to the character class. |
|
Character escape |
|
Add the backspace control character (ASCII 0x08) to the character class. |
|
Character escape |
|
Add the form-feed control character (ASCII 0x0C) to the character class. |
|
Shorthand Character Classes#
Feature |
Syntax |
Description |
Example |
---|---|---|---|
Shorthand |
|
Adds all digits to the character class. Matches a single digit if used outside character classes. The behavior can be controlled by [cudf::strings::regex_flags::ASCII](@ref cudf::strings::regex_flags) to include only |
|
Shorthand |
|
Adds all word characters to the character class. Matches a single word character if used outside character classes. The behavior can be controlled by [cudf::strings::regex_flags::ASCII](@ref cudf::strings::regex_flags) to include only |
|
Shorthand |
|
Adds all whitespace to the character class. Matches a single whitespace character if used outside character classes. The behavior can be controlled by [cudf::strings::regex_flags::ASCII](@ref cudf::strings::regex_flags) to include only |
|
Shorthand |
|
Adds all non-digits to the character class. Matches a single character that is not a digit character if used outside character classes. The behavior can be controlled by [cudf::strings::regex_flags::ASCII](@ref cudf::strings::regex_flags) |
|
Shorthand |
|
Adds all non-word characters to the character class. Matches a single character that is not a word character if used outside character classes. The behavior can be controlled by [cudf::strings::regex_flags::ASCII](@ref cudf::strings::regex_flags) |
[ |
Shorthand |
|
Adds all non-whitespace to the character class. Matches a single character that is not a whitespace character if used outside character classes. The behavior can be controlled by [cudf::strings::regex_flags::ASCII](@ref cudf::strings::regex_flags) |
|
Anchors#
Feature |
Syntax |
Description |
Example |
---|---|---|---|
String anchor |
|
Matches at the start of the string |
|
Line anchor |
|
When [cudf::strings::regex_flags::MULTILINE](@ref cudf::strings::regex_flags) is specified: Matches after each line break in addition to matching at the start of the string, thus matching at the start of each line in the string. |
|
String anchor |
|
Matches at the end of the string as well as before the final line break in the string |
|
Line anchor |
|
When [cudf::strings::regex_flags::MULTILINE](@ref cudf::strings::regex_flags) is specified: Matches before each line break in addition to matching at the end of the string, thus matching at the end of each line in the string. |
|
String anchor |
|
Matches at the start of the string |
|
String anchor |
|
Matches at the end of the string |
|
Word Boundaries#
Feature |
Syntax |
Description |
Example |
---|---|---|---|
Word boundary |
|
Matches at a position that is followed by a word character but not preceded by a word character, or that is preceded by a word character but not followed by a word character. |
|
Word boundary |
|
Matches at a position that is preceded and followed by a word character, or that is not preceded and not followed by a word character. |
|
Quantifiers#
Feature |
Syntax |
Description |
Example |
---|---|---|---|
Greedy quantifier |
|
Makes the preceding item optional. Greedy, so the optional item is included in the match if possible. |
|
Greedy quantifier |
|
Repeats the previous item zero or more times. Greedy, so as many items as possible will be matched before trying permutations with fewer matches of the preceding item, up to the point where the preceding item is not matched at all. |
|
Greedy quantifier |
|
Repeats the previous item once or more. Greedy, so as many items as possible will be matched before trying permutations with fewer matches of the preceding item, up to the point where the preceding item is matched only once. |
|
Lazy quantifier |
|
Makes the preceding item optional. Lazy, so the optional item is excluded in the match if possible. |
|
Lazy quantifier |
|
Repeats the previous item zero or more times. Lazy, so the engine first attempts to skip the previous item, before trying permutations with ever increasing matches of the preceding item. |
|
Lazy quantifier |
|
Repeats the previous item once or more. Lazy, so the engine first matches the previous item only once, before trying permutations with ever increasing matches of the preceding item. |
|
Fixed quantifier |
|
Repeats the previous item exactly |
|
Greedy quantifier |
|
Repeats the previous item between |
|
Greedy quantifier |
|
Repeats the previous item at least |
|
Lazy quantifier |
|
Repeats the previous item between |
|
Lazy quantifier |
|
Repeats the previous item |
|
Groups#
Feature |
Syntax |
Description |
Example |
---|---|---|---|
Capturing group |
|
Parentheses group the regex between them. They capture the text matched by the regex inside them into a numbered group. They allow you to apply regex operators to the entire grouped regex. |
|
Non-capturing group |
|
Non-capturing parentheses group the regex so you can apply regex operators, but do not capture anything. |
|
Replacement Backreferences#
Feature |
Syntax |
Description |
Example |
---|---|---|---|
Backreference |
|
Insert the text matched by capturing groups 1 through 99 |
Replacing |
Backreference |
|
Insert the text matched by capturing groups 1 through 99 |
Replacing |
Whole match |
|
Insert the whole regex match |
Replacing |