Regular Expression Match Operators

Applies to: ✅ Data 360 SQL ✅ Tableau Hyper API

Operators for matching strings against regular expression patterns. Regular expressions provide more powerful pattern matching than LIKE.

Syntax

<string> ~ <pattern>
<string> ~* <pattern>
<string> !~ <pattern>
<string> !~* <pattern>

Operators

Operator Description
~ Matches regular expression, case-sensitive
~* Matches regular expression, case-insensitive
!~ Doesn't match regular expression, case-sensitive
!~* Doesn't match regular expression, case-insensitive

Arguments

Required

  • <string>: The string to match against.
  • <pattern>: The regular expression pattern.

Returns

Returns a boolean value indicating whether the string matches (or does not match) the pattern.

Considerations

  • Regular expressions are more powerful than LIKE patterns, supporting complex patterns like repetition, alternation, and character classes.
  • Unlike LIKE, regular expressions match anywhere within the string by default. Use ^ and $ anchors to match the start and end of the string.
  • For detailed regex syntax, see Regular Expression Syntax.

Examples

Case-Sensitive Match

Match a pattern with case sensitivity.

SELECT 'thomas' ~ '.*thomas.*' AS result;

Returns true.

SELECT 'thomas' ~ '.*Thomas.*' AS result;

Returns false because case does not match.

Case-Insensitive Match

Match a pattern ignoring case.

SELECT 'thomas' ~* '.*Thomas.*' AS result;

Returns true.

Negated Match

Check that a string does not match a pattern.

SELECT 'thomas' !~ '.*Thomas.*' AS result;

Returns true because case-sensitive match fails.

SELECT 'thomas' !~* '.*vadim.*' AS result;

Returns true because the pattern is not found.

Alternation

Match one of multiple patterns.

SELECT 'abc' ~ '(b|d)' AS result;

Returns true because the string contains 'b'.

Start of String

Match patterns at the beginning of a string.

SELECT 'abc' ~ '^a' AS result;

Returns true because the string starts with 'a'.

SELECT 'abc' ~ '^(b|c)' AS result;

Returns false because the string does not start with 'b' or 'c'.

Related Documentation