POSIX Operators

Pattern-matching conditions

Important Notice: Migration of Documentation Website

Please be advised that our documentation website is currently undergoing a migration to a new platform. To ensure you have access to the most up-to-date information, we kindly request that you visit our new documentation website located at:

Official Snowflake Snowconvert Documentation

For any immediate assistance or if you encounter any issues, please contact our support team at [email protected].

Thank you for your understanding.

Description

A POSIX regular expression is a sequence of characters that specifies a match pattern. A string matches a regular expression if it is a member of the regular set described by the regular expression. POSIX regular expression patterns can match any portion of a string. (Redshift SQL Language reference POSIX Operators).

Grammar Syntax

expression [ ! ] ~ pattern

POSIX pattern-matching metacharacters

POSIX pattern matching supports the following metacharacters (all the cases are supported in Snowflake):

POSIX
Description

.

Matches any single character.

*

Matches zero or more occurrences.

+

Matches one or more occurrences.

?

Matches zero or one occurrence.

|

Specifies alternative matches.

^

Matches the beginning-of-line character.

$

Matches the end-of-line character.

$

Matches the end of the string.

[ ]

Brackets specify a matching list, that should match one expression in the list.

( )

Parentheses group items into a single logical item.

{m}

Repeat the previous item exactly m times.

{m,}

Repeat the previous item m or more times.

{m,n}

Repeat the previous item at least m and not more than n times.

[: :]

Matches any character within a POSIX character class. In the following character classes, Amazon Redshift supports only ASCII characters, just like Snowflake: [:alnum:], [:alpha:], [:lower:], [:upper:]

The parameters 'm' (enables multiline mode) and 's' (allows the POSIX wildcard character . to match new lines) are used to achieve full equivalence in Snowflake. For more information please refer to Specifying the parameters for the regular expression in Snowflake.

Sample Source Patterns

Setup data

. : Matches any character

Input Code:

Output Code:

* : Matches zero or more occurrences.

Input Code:

Output Code:

? : Matches zero or one occurrence

Input Code:

Output Code:

^ : Matches the beginning-of-line character

Input Code:

Output Code:

$ : Matches the end of the string.

Input Code:

Output Code:

Usage of collate columns

Arguments with COLLATE specifications are not currently supported in the RLIKE function. As a result, the COLLATE clause must be disabled to use this function. However, this may lead to differences in the results.

Input Code:

Output Code:

If you require equivalence for these scenarios, you can manually add the following parameters to the function to achieve functional equivalence:

Parameter
Description

c

Case-sensitive matching

i

Case-insensitive matching

Known Issues

Known Issues

  1. The behavior of fixed char types may differ. Click here for more information.

  2. Arguments with COLLATE specifications are not currently supported in the REGEXP_COUNT function.

  • SSC-FDM-PG0011: The use of the COLLATE column constraint has been disabled for this pattern-matching condition.

Last updated