expect_column_values_to_not_match_regex_list
How it Works
The expect_column_values_to_not_match_regex_list test from the dbt-expectations package validates that column values do not match any pattern from a list of regular expressions. By default, values must avoid all patterns in the list (match_on: any), but you can configure match_on: all to require that values avoid every pattern simultaneously.
Steps and Conditions
- Column Selection: Choose the column to validate.
- Define Exclusion List: Provide the regex patterns that values must NOT match using
regex_list. - Match Mode: Set
match_ontoany(default) orall. - Execution: Each value is tested against all patterns.
- Outcome: Pass if no values match any pattern (or all patterns for
allmode); fail otherwise.
Example Usage: Data Sanitization
A data sanitization layer wants to ensure that no values in a comment column contain patterns associated with credit card numbers or social security numbers.
models:
- name: customer_comments
columns:
- name: comment_text
tests:
- dbt_expectations.expect_column_values_to_not_match_regex_list:
regex_list:
- "\\b[0-9]{4}[\\s-]?[0-9]{4}[\\s-]?[0-9]{4}[\\s-]?[0-9]{4}\\b"
- "\\b[0-9]{3}-[0-9]{2}-[0-9]{4}\\b"
match_on: anyAny comment matching credit card or SSN patterns triggers a failure for PII remediation.
Interested to Learn More? Try Out the Free 14-Days Trial
One AI-native workspace to build, ship, and monitor dbt™ — without the tool sprawl.
Join industry leaders winning with DinoAI agents
Data engineers and analysts at the most AI-native startups and enterprises use Paradime's DinoAI agents everyday to become market leaders.