> For the complete documentation index, see [llms.txt](https://docs.docontrol.io/docontrol-user-guide/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.docontrol.io/docontrol-user-guide/workflows/define-workflow-settings/action-settings/query/regex-scan.md).

# Regex scan

Regex (regular expression) is a string or pattern sequence of symbols and characters that is searched for in documents. Regular expressions provide a powerful and flexible way to match all characters or portions of text in a string. With the Regex scan action, you can scan for customized patterns that are specific to your organization, such as customer data and sensitive company information, with maximum flexibility.

#### What does a Regex scan look for and what does it return?

A Regex scan uses a deterministic scanning algorithm to detect a specific expression, string or pattern in a file. If you accurately configure a regular expression, the regex scan will find any relevant results in the file and display them in the step output.&#x20;

#### **When to use a Regex scan?**

We recommend you use a Regex scan when you know the textual structure, or pattern, of the keywords you are looking for and would like to view clear, unequivocal results. Alternatively, use a Regex scan when you're looking for proprietary sensitive information that is not considered as personally identifiable information (PII). This could include sensitive internal company items, budget data, or unique customer data.

{% hint style="success" %}

* We recommend you use this [testing site](<https://regex101.com/ >) to build and test regular expressions on sample content. If the expression returns content, the expression is valid.
* For best practices on how to set up a regex scan, see [DoControl videos](/docontrol-user-guide/help/videos.md#regex-scan).
  {% endhint %}

## Use cases&#x20;

Common use cases for running a regex scan include references to salary, internal documents, executives in the company, or specific confidential topics.

An example of a regex string is:

`(\W|^)[\w.-]{0,25}@(yahoo|hotmail|gmail).com(\W|$)`

The results should return any email address match from these domains: yahoo.com, hotmail.com, and gmail.com, such as johndoe\@gmail, <jane@hotmail.com>.

A regex example to match any email address from a specific domain can be found [here](<https://support.google.com/a/answer/1371417?hl=en#Match-Any-Email-Address-from-a-Spec >).

## Supported file types

You can scan text-based files for regex patterns in these apps:

* [Google](#google-regex-scan)
* [Slack](#slack-regex-scan)&#x20;
* [Slack Enterprise](#slack-enterprise-regex-scan)

DoControl supports these files types when running a Regex scan query:

<table><thead><tr><th width="159">App</th><th>File type</th><th>MIME type</th></tr></thead><tbody><tr><td>General</td><td><ul><li>TXT (text)</li><li>CSV (comma separated values)</li><li>TSV (tab separated values)</li><li>PDF (portable document format)</li></ul></td><td><p></p><ul><li>text/plain</li><li>text/csv</li><li>text/tab-separated-values</li><li>application/pdf</li></ul></td></tr><tr><td>Google Drive</td><td><ul><li>GDOC (Google Docs)</li><li>GSLIDES (Google Slides)</li><li>GSHEET (Google Sheets)</li></ul></td><td><p></p><ul><li>application/vnd.google-apps.document</li><li>application/vnd.google-apps.presentation</li><li>application/vnd.google-apps.spreadsheet</li></ul></td></tr><tr><td>Microsoft</td><td><ul><li>DOCX (Word version 2007 and up)</li><li>XLS (Excel up to version 2003)</li><li>XLSX (Excel version 2007 and up), XLT</li><li>PPTX (Powerpoint version 2007 and up)</li></ul></td><td><p></p><ul><li>application/vnd.ms-excel</li><li>application/vnd.openxmlformats-officedocument.spreadsheetml.sheet</li><li>application/vnd.openxmlformats-officedocument.wordprocessingml.document</li><li>application/vnd.openxmlformats-officedocument.presentationml.presentation</li></ul></td></tr></tbody></table>

## Google regex scan

You can define a workflow with a regex scan to detect [keywords or patterns](#regex-patterns) across all Google Drive assets.&#x20;

If a regex pattern is found, your organization will be notified, and can remediate accordingly.

{% hint style="info" %}
Before you run a regex scan for the first time, make sure you enable PII access in **Settings > Admin > Legal consent**. For more information, see [Legal consent for PII.](/docontrol-user-guide/system-management/settings/legal-consent-for-pii.md)
{% endhint %}

<figure><img src="https://3236294211-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MesrnyDMZGYg1V-tOBo%2Fuploads%2FiThcSsCswN00rdSq1kak%2FRegex%20input.png?alt=media&amp;token=ab5b41cf-a049-4225-88b5-a7d22267edb5" alt=""><figcaption><p>Defining a workflow with a regex scan</p></figcaption></figure>

1. For the **App**, select Google Drive.
2. Select the relevant trigger.
3. From the Actions pane, select **Query > Regex scan,** drag it to the canvas and connect it to the trigger.
4. Click the **Regex scan** action to open its settings:
   * **Asset ID** - This field is automatically populated
   * **Lexical list or patterns** - Select a lexical list or [regex pattern](#regex-patterns) from the dropdown or insert a regular expression that you wish to scan for. You can insert multiple patterns.
   * **Error handling -** Choose the relevant option:
     * Break on failure and warning errors
     * Break on failure error only
     * Continue workflow<br>

       <div align="left"><figure><img src="https://3236294211-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MesrnyDMZGYg1V-tOBo%2Fuploads%2FEBbnNRRMee0exqlY9jxq%2Fregex%20scan.png?alt=media&amp;token=19ad5cfd-9cd9-48ec-ada6-921b61b0d27b" alt="" width="375"><figcaption></figcaption></figure></div>
5. Select **Flow control > Conditional** to add a conditional step to determine if the asset contains the regex expression, using the `Has regex matches` macro.
   * If **False** - Add an **End workflow** step.
   * If **True -** Add a relevant remediation action, such as **Remove collaborator**.

{% hint style="success" %}
To extract the results of the regex matches, you can use several predefined macros in any following action step:

* **Regex matches** - list of all matches found
* **Regex matches with index** - list of matches with the corresponding index in document
* **Has regex matches** - True or false, depending if any matches are found.
  {% endhint %}

7. If the regex expression is found, select **Notify > in Slack** or **by email** to send an automatic notification.&#x20;

## Slack regex scan

You can define a workflow with a regex scan to detect [keywords or patterns](#regex-patterns) in a file that's shared in an external Slack channel.&#x20;

If a regex pattern is found, your organization will be notified, and can remediate accordingly.

{% hint style="info" %}
Before you run a regex scan for the first time, make sure you enable PII access in **Settings > Admin > Legal consent**. For more information, see [Legal consent for PII.](/docontrol-user-guide/system-management/settings/legal-consent-for-pii.md)
{% endhint %}

<figure><img src="https://3236294211-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MesrnyDMZGYg1V-tOBo%2Fuploads%2FFCUZ09thy9unG7W3I9eP%2FSlack%20regex%20scan.png?alt=media&amp;token=767b8f9d-44d3-4b0f-9f3a-090fd92b3bcc" alt=""><figcaption></figcaption></figure>

1. For the **App**, select Slack.

2. Select the relevant trigger, for example, User shared sensitive files in external channels.

3. The trigger conditions are automatically populated:
   * **Asset type supports file scanning** - File type supports regex scanning.
   * **Channel is public** - Slack channel is shared.

4. From the Actions pane, select **Query > Regex scan,** drag it to the canvas and connect it to the trigger. Click the action to open its settings.

   * **Asset ID** - This field is automatically populated
   * **Lexical list or patterns** - Select a lexical list or [regex pattern](#regex-patterns) from the dropdown or insert a regular expression that you wish to scan for. You can insert multiple patterns.
   * For **Error handling**, choose the relevant option.

5. Select **Flow control > Conditional** to add a conditional step to determine if the file contains the regex expression, using the `Has regex matches` macro.
   * If **False** - Add an **End workflow** step.
   * If **True -** Add a **Delete** action to remove the shared file.

{% hint style="success" %}
To extract the results of the regex matches, you can use several predefined macros in any following action step:

* **Regex matches** - list of all matches found
* **Regex matches with index** - list of matches with the corresponding index in document
* **Has regex matches** - True or false, depending if any matches are found.
  {% endhint %}

## Slack Enterprise regex scan

You can define a workflow with a regex scan to detect [keywords or patterns](#regex-patterns) in files and messages sent in a public Slack Enterprise channel.&#x20;

If a regex pattern is found, your organization will be notified, and can remediate accordingly.

<figure><img src="https://3236294211-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MesrnyDMZGYg1V-tOBo%2Fuploads%2FZO3FBVY17k6mQtccR2xb%2FSlack%20Enterprise%20regex.png?alt=media&amp;token=94b0302b-97eb-4f55-a646-c63a950ab117" alt=""><figcaption><p>Defining a workflow with a regex scan for Slack Enterprise files or messages</p></figcaption></figure>

1. For the **App**, select Slack Enterprise.
2. Select the relevant trigger, for example, User shared sensitive messages in public channels.
3. From the Actions pane, select **Query > Regex scan,** drag it to the canvas and connect it to the trigger. Click the action to open its settings.
   * **Scan entity** - Select the Slack entity to scan: Message or file (or both).
   * **Lexical list or patterns** - Select a lexical list or [regex pattern](#regex-patterns) from the dropdown or insert a regular expression that you wish to scan for. You can insert multiple patterns.
   * For **Error handling**, choose the relevant option.
4. Select **Flow control > Conditional** to add a conditional step to determine if the message contains the regex expression, using the `Has regex matches` macro.
   * If **False** - Add an **End workflow** step.
   * If **True -** Add a **Delete message** action to remove the shared message.

{% hint style="success" %}
To extract the results of the regex matches, you can use several predefined macros in any following action step:

* **Regex matches** - list of all matches found
* **Regex matches with index** - list of matches with the corresponding index in document
* **Has regex matches** - True or false, depending if any matches are found.
  {% endhint %}

## Output of regex scan

To view the results of your regex scan, go to the specific workflow and view its execution details.

**For example**: If the regex expression `"^test*\n"` is scanned and found in the file contents, it returns this result:\
Matches: `[["index:4", "match: test run"], ["index:100", "testing"]]`

This means the strings were found at character number 4 and 100 in the file contents.

<figure><img src="https://3236294211-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MesrnyDMZGYg1V-tOBo%2Fuploads%2FRHAUkvXBBciA61TWLAGK%2FRegex%20output.png?alt=media&amp;token=7522d846-0ac8-4ccb-919d-400d8f3d7f8c" alt=""><figcaption><p>Output of regex scan</p></figcaption></figure>

## Regex patterns

You can use any of these predefined regex patterns in your regex scan:

<table><thead><tr><th width="296">Regex pattern</th><th>Description</th></tr></thead><tbody><tr><td>Social security number</td><td>US social security number</td></tr><tr><td>Credit Card</td><td>Credit card number</td></tr><tr><td>Swift Number</td><td>International bank code that identifies particular banks worldwide. It's also known as a Bank Identifier Code (BIC)</td></tr><tr><td>IBAN</td><td>International Bank Account Number (IBAN) is an internationally agreed-upon system of identifying bank accounts across national borders to facilitate the communication and processing of cross-border transactions with a reduced risk.</td></tr><tr><td>Medicare Beneficiary Identifier (MBI)</td><td>The Medicare Beneficiary Identifier (MBI) is a randomly generated identifier used to identify all Medicare beneficiaries. It replaced the previously-used SSN-based Medicare HIC Number (HICN).</td></tr><tr><td>US Medicare Health Insurance Claim (HIC)</td><td>Medicare Health Insurance Claim # (HIC) is a unique identifier of a beneficiary used for Medicare entitlement and billing purposes.</td></tr><tr><td>AWS access key</td><td>AWS access keys to make programmatic calls to Amazon Web Services </td></tr><tr><td>AWS secret key</td><td>AWS secret keys to make programmatic calls to Amazon Web Services</td></tr><tr><td>Google API key</td><td>Google keys to make programmatic calls to Google API</td></tr><tr><td>RSA private key</td><td>RSA is a public-key cryptosystem that is widely used for secure data transmission</td></tr><tr><td>Cryptographic private key</td><td>Private encryption key containing a private key reference</td></tr><tr><td>GitHub reference</td><td>Reference to a GitHub repository </td></tr><tr><td>Email</td><td>Email addresses</td></tr><tr><td>URL</td><td>Links and URL structural references</td></tr></tbody></table>

## Regex syntax limitations

When using syntax in the regex scan, be aware of these limitations.

* DoControl uses [RE2 syntax ](https://cran.r-project.org/web/packages/re2/vignettes/re2_syntax.html)for regular expressions.
* You must enter at least five characters in the regex expression; otherwise it might return too many results
* You can enter up to 1000 characters in the regex expression.
* The file size is limited to 10MB.
* If the result is greater than 70 characters, the `Expression too wide` error is returned.
* If it takes more than two minutes to run the regex scan, the `Expression too wide` error is returned.


---

# 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.docontrol.io/docontrol-user-guide/workflows/define-workflow-settings/action-settings/query/regex-scan.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.
