Skip to main content

Extract naming convention values with regex

Create an Automatic dimension with an RE2 pattern that reads a value from each ad name, limit it by date or ad filter, and fix errors.

Written by Daniel von Mirbach

An Automatic dimension reads a value from every ad name with a regular expression (regex), so you keep no list of values. This article shows how to write the pattern, create the dimension, limit it to some ads and fix patterns that return the wrong value.

Who can use this

  • Plans: All plans

  • Roles: Admin and Member. Visitors can't open the Naming Convention settings.

  • Platforms: All platforms

Before you begin

  • Your ad names need a consistent structure, such as fields in the same order with one separator.

  • Collect several real ad names from your account, not only one.

  • For short lists of values or names without structure, use a Manual dimension instead: Set up a naming convention.

How a regex reads a naming convention value

A regex in an Automatic dimension is a search pattern that DatAds runs against the ad name of every ad. DatAds uses the text of the first capture group, the part in round brackets, as the value. Without a capture group, the whole match becomes the value. An ad whose name doesn't match gets no value.

These rules apply to every pattern:

  • DatAds uses the RE2 syntax. Lookahead, lookbehind and backreferences are not supported.

  • A pattern can have up to 500 characters.

  • The pattern can match anywhere in the name. Start it with ^ to match from the beginning.

  • Only the first match in an ad name counts.

  • The pattern is case-sensitive. To ignore upper and lower case, start it with (?i).

  • DatAds saves the value exactly as written in the ad name, including spaces.

Think of an ad name as a train. Each car holds one field, and a separator joins the cars. In the name 2026-08-14 | Video | Sophie | Always On | Cookies | Hook A, a regex can skip three cars and return the fourth, which is Always On.

Write a regex for a field of the naming convention

To write a regex for a field of your naming convention:

  1. Write out your convention and number each field from the left, starting at 1. For example: Date 1, Format 2, Creator 3, Always On or Testing 4, Product 5, Testing Variable 6.

  2. Note the separator. Common separators are | . - and _. The separator must not appear inside a field value. If it does, every field after it shifts by one without any warning.

  3. Use this pattern for position N, with T as your separator: ^(?:[^T]*T){N-1} *([^T]*?) *T

N-1 is the number of fields to skip. The part in round brackets is the value DatAds extracts. The leading and trailing spaces are trimmed, so names with spaces around the separator work too.

For the name 2026-08-14 | Video | Sophie | Always On | Cookies | Hook A and the separator |, these patterns return one field each:

Field

Position

Pattern

Value

Date

1

^ *([^|]*?) *\|

2026-08-14

Format

2

^(?:[^|]*\|){1} *([^|]*?) *\|

Video

Creator

3

^(?:[^|]*\|){2} *([^|]*?) *\|

Sophie

Always On or Testing

4

^(?:[^|]*\|){3} *([^|]*?) *\|

Always On

Product

5

^(?:[^|]*\|){4} *([^|]*?) *\|

Cookies

Testing Variable

6 (last)

^(?:[^|]*\|){5} *([^|]*?) *$

Hook A

To add another field, change only the number in the curly brackets.

Important: For the last field, end the pattern with $ and use [^|] inside the brackets, as in the last row. If a name has an unexpected extra segment after the last field, the pattern returns no value, so you notice the problem. A pattern that ends with (.*)$ silently adds the extra text to the value.

Use the matching characters for other separators. A dot and a pipe need a backslash outside square brackets. The table shows position 4 for each separator:

Separator

Pattern for position 4

Pipe |

^(?:[^|]*\|){3} *([^|]*?) *\|

Dot .

^(?:[^.]*\.){3} *([^.]*?) *\.

Hyphen -

^(?:[^-]*-){3} *([^-]*?) *-

Underscore _

^(?:[^_]*_){3} *([^_]*?) *_

To extract a part of a field instead, put a pattern around it. For example, V(\d+) matches V123 or V45 in a name and extracts 123 or 45.

Create an Automatic dimension with a regex

To create an Automatic dimension:

  1. Go to Settings > Clients, select Manage next to the client, then select Naming Convention.

  2. Select Add Dimension.

  3. In Name, enter the name for reports and filters, for example Format.

  4. Optional: in Description, enter where the value comes from, for example Field 2 of the naming convention.

  5. Under How to define values, select Automatic.

  6. In Value extractor (regex), paste your pattern.

  7. Optional: set Which ads to include and Only index ads created after a date, as described in the next sections.

  8. Select Create.

DatAds shows "Dimension created." The dimension appears with the badges Automatic and Indexing…. When the status is Done, select the row of the dimension. Pattern shows your regex and Detected Values lists the values DatAds found. Check the values on several different ads, not only the one you used to write the pattern. Ads of other campaign types often break the pattern.

The Create Dimension window for an Automatic dimension

If the list shows "No values extracted yet. They appear here after indexing matches your pattern.", wait until the status is Done. If it still shows no values, the pattern matches no ad name.

Include only some ads in an Automatic dimension

Which ads to include limits an Automatic dimension to the ads that match a filter. Ads that don't match get no value. Use it to keep ads out of the dimension, for example recruiting or local campaigns that don't follow your naming convention. A regex can't exclude ads by itself, because RE2 has no lookahead.

To include only some ads:

  1. In the window Create Dimension or Edit Dimension, select Which ads to include.

  2. Choose a property, an operator and a text, for example Campaign Name contains not Recruiting.

  3. Optional: select Add more for another condition, and choose and or or.

  4. Select Create or Save.

The filter can use ad properties such as Campaign Name, Ad Set Name and Ad Name. It can't use metrics. Leave the filter empty to include all ads. When you change the filter of an existing dimension, DatAds indexes all ads again.

When you create a dimension, DatAds copies the conditions of the client's Global Filter into this section, for the platform tab selected in the Global Filter section (Meta by default). Check them and remove what you don't want.

Index only newer ads in an Automatic dimension

Only index ads created after a date skips ads that are older than a date you choose. Use it when your naming convention is new and older ad names don't follow the pattern. It is available when you create a dimension.

To set the start date:

  1. In the window Create Dimension, turn on Only index ads created after a date.

  2. Enter a date, or select Today, 3 months ago or 6 months ago.

  3. Select Create.

DatAds indexes only ads that were created on or after this date, now and in the future. The list shows the badge From and the date, and the edit window shows "Indexing ads created on or after" the date. You can't change the date later. To change it, delete the dimension and create it again. Leave the option off to read all ads, including old ones.

The start date of an Automatic dimension

Fix errors in a regex for a naming convention

A regex that DatAds can't accept stops the save. When you create a dimension, DatAds shows "Failed to create extractor." and doesn't keep the dimension. When you edit a dimension, DatAds shows "Failed to update regex pattern. Please refresh the page and try again." The usual causes are a pattern with more than 500 characters, or syntax that RE2 doesn't support: lookahead such as (?=...), lookbehind such as (?<=...) and backreferences such as \1.

The table lists other symptoms:

Symptom

Cause

Fix

No value on some ads

The name has fewer fields, another separator, or it doesn't follow the convention

Fix the ad names in the ad platform, use a Manual dimension for these ads, or limit the dimension with Which ads to include

The value has spaces at the start or end

Spaces around the separator, and a pattern without trimming

Use the patterns in this article. They trim the spaces around the value.

The value is far too long

The separator appears inside a field value

Choose a separator that no value contains

All fields are off by one

N-1 and N are mixed up

Position 4 means {3}

Every ad has the same value, or the whole match is the value

The round brackets are missing or surround the wrong part

Put the brackets around only the value you want

A value in capitals or lower case is missing

The pattern is case-sensitive

Start the pattern with (?i)

The last field has extra text

A segment follows the last field, and the pattern ends with (.*)$

End the pattern with $ and use [^|] inside the brackets, as in the last row of the pattern table, so that it fails visibly

Let AI write the regex for your naming convention

You can ask an AI assistant to write the regex. Copy this prompt, and replace the parts about your convention and your ad names:

I need a regex for DatAds. DatAds extracts values from ad names with RE2 syntax. The regex must be RE2-compatible, with no lookahead and no lookbehind. The value to extract must be in exactly one capture group. The regex must start with ^ and must trim spaces around the separator. My naming convention is: Date | Format | Creator | Always On/Testing | Product | Testing Variable. Here are several real ad names from my account: 2026-08-14 | Video | Sophie | Always On | Cookies | Hook A, 2026-08-12 | Static | Nadja | Testing | Brownies | Hook C. Give me a table with one regex per field and one sentence about what each regex does. Flag every field that can't be extracted cleanly.

Give the assistant several real ad names, because it then spots spaces and inconsistent names. Test the result before you save it. Paste it into regex101.com, select Golang as the flavor, which matches RE2, and check the highlighted value on each name.

Related articles

Did this answer your question?