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 

1<string> ~ <pattern>
2<string> ~* <pattern>
3<string> !~ <pattern>
4<string> !~* <pattern>

Operators 

OperatorDescription
~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.

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

Returns true.

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

Returns false because case does not match.

Case-Insensitive Match 

Match a pattern ignoring case.

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

Returns true.

Negated Match 

Check that a string does not match a pattern.

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

Returns true because case-sensitive match fails.

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

Returns true because the pattern is not found.

Alternation 

Match one of multiple patterns.

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

Returns true because the string contains ‘b’.

Start of String 

Match patterns at the beginning of a string.

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

Returns true because the string starts with ‘a’.

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

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

Related Documentation