Function table / Strings / REGEXP_MATCH

REGEXP_MATCH: from Tableau to SQL

Tests whether a regular expression matches anywhere in a string. Below, 8 sample rows go through the calculation and through the SQL, and both return the same numbers.

Calculated field

REGEXP_MATCH([label], 'birch|ash')

Sample data

labelquantityamountflag
cedar cedar 6512.8True
ORCHID-west66-7.6False
maple-east670null
willow north6825.3True
birch-birch694.9False
pine/south70-1.2null
ash719True
nullnullnullnull

The same calculation as SQL

SELECT regexp_matches(label,'birch|ash') AS result FROM input

Runs the example above.

Result

result
False
False
False
False
True
False
True
null

Same rows from the calculation and from the SQL in DuckDB.

Where a naive translation goes wrong

  • Replacing REGEXP_MATCH with regexp_full_match(label,'birch|ash') changes the shown values or null handling.

    Naive SQL

    SELECT regexp_full_match(label,'birch|ash') AS result FROM input
    result
    False
    False
    False
    False
    False
    False
    True
    null

    Matches the calculation

    SELECT regexp_matches(label,'birch|ash') AS result FROM input
    result
    False
    False
    False
    False
    True
    False
    True
    null

Signature

REGEXP_MATCH(string, constant_pattern)