REGEXP_MATCH(string, pattern) is true when any part of the string matches the pattern. DuckDB's regexp_matches() searches the same way. regexp_full_match() requires the pattern to cover the whole string, so it returns false far more often.
Updated · Checked on the xmetric engine
What is the syntax?
REGEXP_MATCH(string, pattern)
string
the text to test.
pattern
a constant regular expression.
Returns true if the pattern matches part of the string, false if not, null for a null string.
What does it return, and what is the SQL?
Each example runs on the same 7 sample rows twice: the Tableau formula on the xmetric engine, and the SQL in DuckDB.
Which codes contain a digit?
Tableau
REGEXP_MATCH([Code], '\d')
SQL (DuckDB)
SELECTregexp_matches(Code, '\d') AS result
FROM input
ORDERBY id
Every code but X.
Code
Result
A-12-x
true
B-71
true
C-301-yz-9
true
a_1
true
X
false
D-4-y
true
null
✓ The Tableau formula and the SQL return the same 7 rows.
Where does a straight translation go wrong?
Common mistake
Why does regexp_full_match reject A-12-x?
A full match must consume the whole string, and -x is left over. REGEXP_MATCH only needs the pattern to occur.
Tableau
REGEXP_MATCH([Code], '^[A-Z]-\d+')
Tempting SQL
SELECTregexp_full_match(Code, '^[A-Z]-\d+') AS result
FROM input
ORDERBY id
SQL that matches
SELECTregexp_matches(Code, '^[A-Z]-\d+') AS result
FROM input
ORDERBY id
Code
Tableau
Tempting SQL
SQL that matches
A-12-x
true
false
true
B-71
true
true
true
C-301-yz-9
true
false
true
a_1
false
false
false
X
false
false
false
D-4-y
true
false
true
null
null
null
✓ The SQL that matches returns the Tableau result on every row; the marked cells are where the tempting SQL differs.
Does an anchored start still match a substring?
The pattern must start the string but may stop before its end. Columns 1 to 7 are the sample rows, by id.