Matches Regex

Detects values of a field that do not match a regular expression.

The Matches Regex monitor checks that a string field only contains values that match a regular expression (regex) you provide.

When to Use

  • Codes with a fixed format: A code field must follow a fixed convention, such as a two-letter country code in uppercase (FR, DE).
  • Stricter formats: The built-in Is a Phone Number or Is UUID formats do not match the convention of your data, for example phone numbers that must start with +.

How It Works

For each data point, Sifflet counts the rows where the field value does not match the regular expression, and computes:

  • Count (default value mode): The number of invalid rows.
  • Percentage: The share of invalid rows among the rows checked for the data point, in percent. These are the rows of the period in incremental scan mode (for example, all the rows created that day), or all the rows of the table in full dataset scan mode. Rows excluded by the where clause are not counted.

Null values are not counted as invalid. To detect them, use Nulls.

The default static threshold fails when the data point is greater than 0, that is, as soon as one value is invalid.

Sifflet runs the regular expression with the regex function of your data source (for example, REGEXP_CONTAINS on BigQuery or REGEXP_LIKE on Snowflake), so the supported syntax depends on the data source. Whether the expression must match the whole value or only part of it also depends on the data source: start the expression with ^ and end it with $ to require a full match everywhere.

Example

You want every order country to be a two-letter code. Create a Matches Regex monitor on orders with the following settings:

  • Column to monitor: country.
  • Regex syntax: ^[A-Z]{2}$.
  • Monitoring mode: Incremental scan, with created_at as the time window column and a daily time-based data aggregation.
  • Threshold: Static, Greater than 0 (default).

On June 14, a new sales website sends full country names, and 450 orders of the day have the country France or Germany. The data point of June 14 is 450, greater than 0, so the monitor fails.

Configure the Monitor

📝 Note: This template is only available on Athena, BigQuery, Databricks, MySQL, Oracle, PostgreSQL, Redshift, and Snowflake. See Supported Data Sources.

Matches Regex Settings

SettingDescriptionDefault
Column to monitorThe string field to check.None
Regex syntaxThe regular expression that valid values must match.None

Common Settings

  • Value mode: Count (default) or Percentage.
  • Threshold: Static (default), relative, or dynamic. See Thresholds.
  • Scan mode: Incremental or full dataset. See Scan Modes.
  • Where clause and group by: See Where Clause, Group By, and Joins.
  • Joins: Join a second dataset to filter or group by its fields. See Joins.

Monitor as Code

The monitor kind is FieldFormat, with format.kind: Regex. The following YAML creates the monitor of the example:

kind: FieldFormat
field: country
format:
  kind: Regex
  regex: "^[A-Z]{2}$"
timeWindow:
  field: created_at
  firstRun: P365D
  frequency: P1D
ParameterRequiredDescription
fieldYesThe string field to check.
format.kindYesRegex.
format.regexYesThe regular expression that valid values must match. In YAML, escape backslashes (\\d) or use single quotes.

For the shared parameters, see the Parameters reference.

Related Templates


Did this page help you?