> For the complete documentation index, see [llms.txt](https://help.impact.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://help.impact.com/brand/what-would-you-like-to-learn-about/platform-features/promo-codes/regular-expression/regex-explained.md).

# Regex Explained

Regex (or Regular Expression) is a code that you can use to match text for a general case and is useful when matching promo codes. Regex is case-sensitive, so be sure to set your regex up in the case that matches your promo codes.

* There are three main logic cases for regex and promo codes: `starts with`, `ends with`, and `contains`.
* For this example, the base of our promo code is `SUMMER`.

{% tabs %}
{% tab title="Starts with" %}
You’ve issued a range of summer promo codes to partners, `SUMMER20OFF`, `SUMMER10`, and `SUMMER25`. We want to match them all to credit our partners, how do we go about it? We would use the `starts with` logic. Simply add a period and a star at the end of your base promo code.

The regex should be exactly `^(SUMMER).*`

This will automatically match any promo codes starting with `SUMMER` and ending with any other characters. Any codes not starting with `SUMMER` will not be matched.
{% endtab %}

{% tab title="Ends with" %}
You’ve issued a range of summer promo codes to partners, `20OFFSUMMER`, `10SUMMER`, and `25SUMMER` where the promo code always ends in `SUMMER`. How do we match them? We would use the `ends with` logic. Simply add a period and a star at the beginning of your base promo code and add a $ to specify the anchor of your string.

The regex should be exactly `^.*(SUMMER)$`

This will automatically match any promo codes starting with other characters and ending with `SUMMER`. Any codes not ending with `SUMMER` will not be matched.
{% endtab %}

{% tab title="Contains" %}
You’ve issued a range of summer promo codes to partners, `20SUMMER`, `SUMMER20OFF`, and `EXTRASUMMER10`, where `SUMMER` appears somewhere in the code. We would use the `contains` logic. Add `.*` before and after your base promo code, and wrap the expression in the ^ and $ anchors.

The regex should be exactly `^.*(SUMMER).*$`

This regex matches a promo code containing `SUMMER` anywhere in the code. Any codes that do not contain `SUMMER` will not be matched.
{% endtab %}
{% endtabs %}

For more complicated expressions, please reach out to your CSM or [contact support](https://app.impact.com/support/portal.ihtml?createTicket=true\&accountType=ADVERTISER) for help.

{% hint style="success" %}
**Note:** You can remove regex case sensitivity by adding `(?i)` after `^` in your regex.
{% endhint %}

## Example

```programlisting
^(?i)(SUMMER).*
```


---

# 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://help.impact.com/brand/what-would-you-like-to-learn-about/platform-features/promo-codes/regular-expression/regex-explained.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.
