> For the complete documentation index, see [llms.txt](https://docs.sdv.dev/sdmetrics/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.sdv.dev/sdmetrics/data-metrics/diagnostic/regexformatadherence.md).

# RegexFormatAdherence

This metric captures whether the synthetic data adheres to a specific Regex format.

## Data Compatibility

* **ID** : This metric is meant for ID columns (like primary and foreign keys) with specific Regex formats.

*This metric ignores missing values.*

## Score

**(best) 1.0**: All values in the synthetic data respect the specified Regex format

**(worst) 0.0**: No value in the synthetic data respects the specified Regex format

## How does it work?

This metrics checks each individual value of the synthetic data column to see if it follows the Regex format that is provided. The score is the proportion of synthetic data values that match the Regex format.

{% hint style="info" %}
**Named capture groups are treated specially.** In some cases, your Regex format might contain named capture group such as `(?P<country>[A-Z]{2})-[0-9A-Z]{5}`. This indicates a specific 2-letter code (country) followed by a random 5-character string, for example `US-45PL3` or `CA-10P3R`.&#x20;

In such cases, this metric will parse out the groups that are available in the real data and ensure that only those values appear in the synthetic data. For example if the real data contained prefixes `US`, `CA` and `MX`, then it will explicitly look for those named groups in the synthetic data. If the named value cannot be found in the real data, then the synthetic value would not match the Regex.
{% endhint %}

## Usage

To manually apply this metric, access the `single_column` module and use the `compute` method.

```python
from sdmetrics.single_column import RegexFormatAdherence

RegexFormatAdherence.compute(
    real_data=real_table['purchase_date'],
    synthetic_data=synthetic_table['purchase_date'],
    regex_format='(?P<country>[A-Z]{2})_[0-9A-Z]{5}'
)
```

**Parameters**

* (required) `real_data`: A pandas.Series object with the column of real data
* (required) `synthetic_data`: A pandas.Series object with the column of synthetic data&#x20;
* (required) `regex_format`: A string containing the Regex format to check against. For more information, see [Python's re module](https://docs.python.org/3/library/re.html).

## FAQs

<details>

<summary>Does this metric use real data?</summary>

If the real data doesn't match the provided Regex, then the metric will provide a warning but it will still continue to check the synthetic data.

If the real data doesn't match the provided Regex and there is a named capture group, then the metric cannot be computed and the score is NaN.

</details>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.sdv.dev/sdmetrics/data-metrics/diagnostic/regexformatadherence.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
