> For the complete documentation index, see [llms.txt](https://docs.tonic.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.tonic.ai/app/api/quick-start-guide/tonic-api-generator-assignment/generator-api-reference/generator-api-ref-regex-mask.md).

# Regex Mask (RegexMaskGenerator)

The [Regex Mask](/app/generation/generators/generator-reference/regex-mask.md) generator uses regular expressions to parse strings and replace specified substrings with the output of specified generators. The parts of the string to replace are specified inside unnamed top-level capture groups.

## Link object structure <a href="#generator-api-regex-mask-link-object" id="generator-api-regex-mask-link-object"></a>

The Regex Mask generator does not in itself support linking or consistency or allow you to configure differential privacy.

Each link object identifies a regular expression and the generators to apply to the resulting capture groups.

The `metadata` object for each link object is populated from the [`RegexMaskMetadata`](https://app.tonic.ai/apidocs/index.html#/models/RegexMaskMetadata) object, which includes:

* Whether to replace all matches or only the first match.
* The regular expression used to identify the capture groups to replace.
* The list of generator types to apply to each capture group. The first sub-generator is applied to the first capture group, the second sub-generator to the second group, and so on.
* In the `captureGroupMetadata` object, the configuration for each generator.

```json
{
  "schema": "string",
  "table": "string",
  "column": "string",
  "metadata": {
    "generatorId": "RegexMaskGenerator",
    "presetId": "RegexMaskGenerator",
    "replaceAllMatches": boolean,
    "pattern": "string",
    "captureGroupMetadata": [
      {
              //Metadata for a capture group generator
      }
    ]
  }
}
```

## Example replacement <a href="#generator-api-regex-mask-replacement" id="generator-api-regex-mask-replacement"></a>

The following example replacement for the Regex Mask generator provides two expressions.

For the first expression, the generator is configured to only replace the first match. There are two capture groups. For the first capture group, the Address generator applies a country value, and consistency is disabled. For the second capture group, the Passthrough generator is applied.

For the second expression, the generator is configured to replace all of the matching values. The Business Name generator is applied with consistency disabled.

```json
{
  "name": "summary",
  "schema": "public",
  "table": "projects",
  "links": [
    {
      "schema": "public",
      "table": "projects",
      "column": "summary",
      "metadata": {
        "generatorId": "RegexMaskGenerator",
        "presetId": "RegexMaskGenerator",
        "replaceAllMatches": false,
        "pattern": "^(\\d{3})(.*)$",
        "captureGroupMetadata": [
          {
            "generatorId": "AddressGenerator",
            "addressType": "Country",
            "isConsistent": false
          },
          { 
            "generatorId": "PassthroughGenerator"
          }
        ]
      }
    },
    {
      "schema": "public",
      "table": "projects",
      "column": "summary",
      "metadata": {
        "generatorId": "RegexMaskGenerator",
        "presetId": "RegexMaskGenerator",
        "replaceAllMatches": true,
        "pattern": "-([a-z]*)",
        "captureGroupMetadata": [
          {
            "generatorId": "BusinessNameGenerator",
            "isConsistent": false
          }
        ]
      }
    }
  ]
}
```


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.tonic.ai/app/api/quick-start-guide/tonic-api-generator-assignment/generator-api-reference/generator-api-ref-regex-mask.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
