Skip to content

Regex for SEO: Tested Patterns for Search Console, GA4, Data Studio and Crawlers

Regex for SEO means filtering Search Console, GA4, Data Studio and crawler data with regular expressions. Search Console matches any part of a query or URL and ignores case, while GA4's "matches regex" has to match the whole value and is case-sensitive. Both run Google's RE2 engine, which rejects lookahead, so test each pattern before trusting the numbers.

By , founder of Slibur

12 min read

Regex for SEO: Tested Patterns for Search Console, GA4, Data Studio and Crawlers
In this article

Those differences catch people who copy patterns between tools. A filter that works in a crawler can be refused one tab over, and a pattern that returns hundreds of rows in Search Console can return none in GA4.

Writing regex is also a job people now hand to ChatGPT, one of the places where doing SEO with ChatGPT helps and sometimes fails. The pattern it gave us for "contains one word but not another" is a good example, and the fix is near the end.

The regex syntax most SEO filters need

You can read nearly any pattern a colleague or an AI hands you with these symbols:

  • | means or: boots|shoes matches either word.
  • ^ anchors the start: ^how matches "how to tie a tie" but not "know how".
  • $ anchors the end: \.pdf$ matches URLs that end in .pdf.
  • . is any single character, so a literal dot needs a backslash: example\.com.
  • * repeats the previous item zero or more times, and .* means "anything, or nothing".
  • + repeats it one or more times: \d+ is one or more digits.
  • ? makes the previous item optional: reviews? matches review and reviews.
  • ( ) groups alternatives: /(blog|guides)/ matches either folder.
  • [ ] is one character from a set: [0-9] is any digit, the same as \d.
  • \s is a whitespace character, such as a space, and \S is anything that isn't one.
  • \b is a word boundary: \bseo\b matches "seo tools" but not "seoul".
  • {n,m} sets a count: [0-9]{4} is exactly four digits, and {2,} means two or more.

Two habits prevent most errors. Put a backslash before any character you mean literally (dots, question marks, plus signs, parentheses). And pin short words with \b or ^, because a partial match finds is inside "crisis". Google's Search Console filtering help (opens in a new tab) lists the most common of them, from . and | to \d, \s and ^, with its own examples.

Which regex engine each SEO tool runs

"Regex" isn't one language. Each tool picks an engine and a default way of matching, and those two choices decide whether a pattern copied from a blog post returns the right rows.

ToolEngineDefault matchUpper and lower caseLimits and quirks
Search Console, Performance reportRE2Partial: the pattern can match anywhereIgnored; start with (?-i) to respect itFiltering drops anonymized queries, so totals shrink
Search Console APIRE2includingRegex and excludingRegex operatorsNot stated4,096 characters per filter
GA4 report filtersRE2Whole value with "matches regex"; part of it with "matches partial regex"Respected250 characters per regex
Data Studio (formerly Looker Studio)RE2REGEXP_MATCH needs the whole value; REGEXP_CONTAINS takes partRespected; (?i) ignores itBackslashes in filter conditions need doubling
Google Sheets, REGEXMATCHRE2, without Unicode character classesPart of the textAdd (?i) to ignore itText only, not numbers
Excel, REGEXTESTPCRE2Any part of the textRespected; a third argument of 1 ignores itMicrosoft 365 and Excel for the web
Screaming FrogJavaPartial for Include and ExcludeRespected (Java's default); (?i) ignores itTests the URL-encoded address
Apache RewriteRule, Nginx rewritePCREPartial unless you anchor itRespected; [NC] in Apache or ~* in Nginx ignores itIn .htaccess the path loses its leading slash
robots.txtNonePath prefix, with * and $ onlyRespectedNot regex at all

What RE2 refuses

RE2 is Google's engine. Its README puts safety first and promises match time that grows linearly with the input, which is why it leaves out features that need backtracking. Its syntax page on GitHub marks these as not supported: lookahead (?=...) and negative lookahead (?!...), lookbehind (?<=...) and (?<!...), backreferences such as \1, atomic groups and possessive quantifiers. It also rejects counted repetitions above 1000.

Search Console, GA4, Data Studio and Sheets all inherit those limits. Java, which Screaming Frog uses, and PCRE2, which Excel uses, accept lookarounds and backreferences. So the pattern that works in your crawler is not proof that it will work in your reports.

Contains or whole value: Search Console vs GA4

The same pattern returns different rows in the two Google tools. In Search Console, blog matches any URL with blog anywhere in it. In GA4, a filter set to "matches regex" compares the pattern with the entire value, so blog finds only a page path that is exactly blog.

Google's GA4 filter help (opens in a new tab) lists four regex conditions: matches regex, matches partial regex, does not match regex and does not match partial regex. Pick a partial one when you mean "contains", or wrap the pattern as .*blog.*.

Case flips as well. Search Console ignores it unless the pattern starts with (?-i), so (?-i)Acme skips "acme login". GA4 respects it, which means /blog/.* misses /Blog/Regex. CMS page paths with capital letters are where this bites.

Screaming Frog: Java regex on encoded URLs

Screaming Frog's configuration guide says the SEO Spider uses the Java regex library. Exclude does partial matching against the URL-encoded address, so a pipe inside a URL has to be written as %7C and a question mark needs a backslash, as in \?price. When a URL is full of special characters, wrapping the whole line in \Q and \E makes every character literal.

The Include section describes partial matching, yet its troubleshooting note says the pattern must match the whole URL. Writing .*/blog/.* works under either reading. Include also needs the start page to link to at least one matching URL, or the crawl stops after one page. In custom extraction the dot matches new lines, and heavy patterns slow the crawl down.

robots.txt is not regex

Google's robots.txt specification (opens in a new tab) supports two wildcards in paths and nothing else: * for any run of characters and $ for the end of the URL. Dots and question marks are literal, rules match from the start of the path, and matching is case-sensitive.

So Disallow: /*.php$ blocks paths that end in .php, and Disallow: /*?sort= blocks URLs whose query string starts with that parameter; add Disallow: /*&sort= to catch it in any other position. A pipe or a character class does nothing useful there.

Redirect rules: PCRE on the server

Redirect rules for a site migration are another place SEO regex runs, and there the engine is PCRE. Apache's mod_rewrite documentation says it uses the PCRE2 library, and Nginx's rewrite module changes URIs with PCRE regular expressions, so lookarounds work. Case is respected unless you add the [NC] flag in Apache or use ~* in Nginx.

One trap catches many .htaccess files. In per-directory context, Apache matches the path without its leading slash, so a pattern such as ^/old-blog/(.*)$ never matches there; write ^old-blog/(.*)$. RewriteRule also stops before the query string, so matching a parameter takes a RewriteCond on %{QUERY_STRING}.

A tested regex library for Search Console

Every pattern below is generic: replace acme, example.com and the folder names with your own. Each one was run against the sample strings in its comments, under Search Console's rules (partial match, case ignored). Paste the pattern line alone, without the comments.

Query patterns

# 1. Questions: queries that start with a question word
^(who|what|when|where|why|how|which|can|does|is|are|should)\b
#    matches: how to fix a leaking faucet, which crm is best
#    skips:   island vacation, howard stern

# 2. Brand and misspellings (acme is a placeholder)
\b(acme|acmee|akme|acme ?co)\b
#    matches: acme login, ACME pricing, akme reviews, acmeco coupon
#    skips:   acmes, pharmacmed

# 3. Comparison and review modifiers
\b(best|top|vs|versus|alternatives?|reviews?|compare|comparison)\b
#    matches: best running shoes, zoom vs teams, trello alternatives
#    skips:   stopwatch online, reviewer jobs

# 4. Price and purchase words
\b(price|prices|pricing|cost|costs|cheap|cheapest|buy|deal|deals|coupon)\b
#    matches: roof replacement cost, buy standing desk
#    skips:   buyer persona template, costume ideas

# 5. Long queries: six words or more
(\S+\s+){5,}\S+
#    matches: how long does it take to grow tomatoes
#    skips:   how to tie a tie

# 6. Queries with a year
\b20[0-9]{2}\b
#    matches: best laptops 2026, 2027 tax brackets
#    skips:   route 2026a

# 7. Local intent
\b(near me|nearby|open now|closest)\b
#    matches: dentist near me, pharmacy open now
#    skips:   nearest neighbor algorithm

The first two are the pair most people start with, and the guide to (not provided) keywords shows how they fill in for the keywords Analytics hides. Use pattern 2 with "Matches regex" for branded queries and "Doesn't match regex" for everything else.

Search Console has also had a built-in branded queries filter since Google announced it on November 20, 2025. It works only on top-level properties with enough queries and impressions, so the regex stays the fallback for URL-path and subdomain properties and for smaller sites. The guide to branded and non-branded clicks as a KPI covers when to trust the built-in version.

No anchors are needed in pattern 5, because Search Console only has to find six words somewhere in the query. To set short and long queries side by side, the word-count pair in the long-tail keyword guide does the job.

Page patterns

The Pages filter tests the full URL, protocol and host included, so a pattern that starts with ^/blog/ matches nothing. Start with ^https:// or leave the start open.

# 8. One folder (escape the dots in the host)
^https://www\.example\.com/blog/
#    matches: https://www.example.com/blog/regex-guide
#    skips:   https://www.example.com/about/blog/

# 9. Several folders anywhere in the path
/(blog|guides|resources)/
#    matches: .../guides/setup, .../resources/
#    skips:   .../blogging-tips, .../guide/

# 10. URLs with specific parameters
(\?|&)(sort|page|utm_[a-z]+)=
#    matches: .../shoes?sort=price, .../x?a=1&utm_source=news
#    skips:   .../sort-guide, .../page/2/

# 11. Any URL with a query string
\?

# 12. Dated URLs (year and month folders)
/20[0-9]{2}/[0-1][0-9]/
#    matches: .../2026/11/regex-guide, .../news/2025/03/story
#    skips:   .../2026-guide

# 13. Language or country folders
^https://www\.example\.com/(es|fr|de|en-gb)(/|$)
#    matches: .../es/, .../de/preise, .../en-gb
#    skips:   .../esports/, .../blog/de/

# 14. PDF files
\.pdf$
#    matches: .../files/guide.pdf
#    skips:   .../files/guide.pdf?v=2

News sites use the dated-URL pattern to isolate recent stories when the CMS puts the date in the path, and the news SEO guide turns it into a rough Top Stories view. The language-folder pattern splits a multi-market site by folder, the first cut of the country checks in an international SEO audit. Its (/|$) ending is what stops /es from also catching /esports.

Regex in GA4, Data Studio and spreadsheets

GA4 page paths

Report filters and explorations are where most SEO regex goes in GA4, and Google's regex help for Analytics (opens in a new tab) adds data filters, key events, segments, audiences, content groups and custom channel groups. It also says matching is full and case-sensitive by default: San Francisco returns only San Francisco, while .*San Francisco.* also returns South San Francisco.

# Page path, condition "matches regex" (whole value)
/blog/.*
#    matches: /blog/, /blog/regex-guide
#    skips:   /en/blog/x, /blog, /Blog/x

# Same folder, condition "matches partial regex"
^/blog/

# A fixed set of pages, with or without the trailing slash
/(pricing|plans|demo)/?
#    matches: /pricing, /pricing/, /demo/
#    skips:   /pricing/enterprise

# Ignore case with the RE2 flag (GA4's help doesn't document it: test it on your own property)
(?i)/blog/.*

A regex in a GA4 report filter stops at 250 characters, so a long list of product slugs won't fit in one box. Split it instead: a filter takes up to five conditions, values inside one condition are combined with OR, and separate conditions with AND. GA4's help also warns against ending an expression with |. A trailing bar leaves an empty alternative, and under a partial match an empty alternative matches every row.

One pattern you no longer have to write is the one for visits from AI assistants. GA4's default channel group now files ChatGPT, Gemini, Copilot and similar sources under AI Assistant, and the utm_source=chatgpt.com guide has the source regex for an exploration that puts every assistant in one table.

Data Studio, formerly Looker Studio

Google brought back the Data Studio name for Looker Studio in April 2026, and said existing reports would move over with no action needed. Its regex functions run RE2 and respect case unless the pattern starts with (?i).

REGEXP_MATCH must match the entire value, so REGEXP_MATCH(Page, 'blog') is false for /blog/regex-guide. REGEXP_CONTAINS(field, 'pattern') behaves like REGEXP_MATCH(field, '.*pattern.*') and is the one to reach for when you mean contains. In filter conditions a backslash has to be doubled, so a literal dot becomes \\..

Google Sheets and Excel

Spreadsheets split along the same line. Google Sheets' REGEXMATCH runs RE2, minus Unicode character classes, while Excel's REGEXTEST, REGEXEXTRACT and REGEXREPLACE use PCRE2, which accepts lookarounds. A pattern built from alternatives, \b, ^ and $ works in both. Excel for SEO has the IFS formulas that sort a Search Console export into brand, question and comparison groups.

Mistakes that quietly skew a report

None of these throw an error. The report loads, the numbers look plausible, and they are wrong.

  • Unescaped dots. ^https://www.example.com/blog/ also matches wwwXexample.com, because each dot is a wildcard. It rarely matters in an include, but in an exclusion it can remove more than you meant. Write www\.example\.com.
  • Short words without boundaries. is matches "crisis hotline". With ^is\b it no longer does.
  • Partial versus whole. blog works in Search Console and returns nothing useful under GA4's "matches regex".
  • Case. GA4 and Data Studio respect it, Search Console ignores it unless told otherwise, and a mixed-case CMS path will slip past a lowercase pattern.
  • A trailing bar. acme|akme| matches every query, so with "Doesn't match regex" the report goes empty.
  • Length. GA4's report filters cap a regex at 250 characters and the Search Console API at 4,096 per filter. Fold variants together where you can: acme ?co covers acmeco and acme co.
  • Comparing filtered totals with the chart. Search Console's help says filtering by query or URL can change totals because of data truncation and anonymized queries, so filtered clicks won't add up to the unfiltered line.

How to test a pattern before you trust it

A pattern is ready when it passes on real strings, first in the right engine and then in the tool itself.

  1. Pull a dozen real strings from an export: some that should match and some that shouldn't, including the near misses.
  2. Paste the pattern and the strings into regex101 and pick the flavor that matches the tool. Golang follows RE2 syntax, so use it for Search Console, GA4, Data Studio and Sheets; use PCRE2 for Excel and Java for Screaming Frog.
  3. Reproduce the tool's match mode. For GA4's "matches regex" and REGEXP_MATCH, wrap the test in ^(...)$. For Search Console, turn on the case-insensitive flag.
  4. Run it in the tool on a short date range and check the row count. Then run the same pattern with "Doesn't match regex": the two together should cover the export, apart from anonymized queries.
  5. Save the final pattern in a shared doc with a one-line comment and the date, so the next person knows what it catches.

Slibur dataChatGPT, United States, 4 answers, November 22, 2026

What ChatGPT got right and wrong when we asked for SEO regex

We asked ChatGPT four questions on November 22, 2026, from the United States: the most useful Search Console patterns, how to filter out branded queries, how to filter page paths in GA4, and how to find queries that contain one word but exclude another.

The first three answers cited only support.google.com (four Google help pages, one of them twice, and a community thread), and their basics held up: RE2, partial and case-insensitive matching in Search Console, full matching in GA4. The fourth cited nothing and recommended this:

^(?=.*shoes)(?!.*used).*$

That is a lookahead plus a negative lookahead, both on RE2's not-supported list, so Search Console can't run it. In a separate answer, the same assistant had said negative lookaheads "generally are not available" there.

Smaller slips showed up as well. The brand pattern listed acmе with a Cyrillic letter е that looks identical to the Latin e, so that alternative could never match an English query. The same answer dated the built-in branded queries filter to March 2025, while Google announced it on November 20, 2025. And the GA4 answer got full matching right but never mentioned "matches partial regex", case sensitivity or the 250-character cap.

How to fix a pattern ChatGPT or Claude writes

Asking an assistant for a pattern saves time, as long as you test what comes back. Lookarounds are the standard shortcut for "contains A but not B" in PCRE and JavaScript, so assistants reach for them. RE2 has no "and not" operator, so split the job into two conditions:

Condition 1, Matches regex:        \bshoes\b
Condition 2, Doesn't match regex:  \bused\b
#    keeps: running shoes, best shoes for hiking
#    drops: used running shoes, where to buy used shoes, shoestring budget

Where the second condition lives depends on the tool. GA4 takes it in the same filter, with "matches partial regex" and "does not match partial regex" as the two conditions, since separate conditions combine with AND. The Search Console API (opens in a new tab) offers includingRegex and excludingRegex operators, and every filter in a group must match. In the Search Console interface, filter on the positive pattern, export, then drop the rows with the excluded word in a sheet.

A better prompt avoids most of the cleanup:

  • Name the engine and the tool: "an RE2 regex for the Google Search Console query filter, with no lookahead, lookbehind or backreferences".
  • State the match mode: partial and case-insensitive for Search Console, whole value and case-sensitive for GA4's "matches regex".
  • Ask for strings that should and shouldn't match, then run them yourself, because the assistant's own examples can be wrong too.
  • Type brand names yourself instead of copying them from the answer, which removes look-alike characters.

Regex shows what people typed, not what AI says about you

Every pattern in this library works on clicks and impressions from Google. None of them can tell you whether ChatGPT mentions your brand when a customer asks the same question in a chat, because that answer never reaches Search Console.

The nearest thing to a "Doesn't match regex" filter for AI answers is a list of the questions where you never come up. Slibur keeps that list: it tracks the questions you choose in ChatGPT, Google AI Overviews, Claude, Perplexity and Grok, and its dashboard starts with the ones where no assistant names or cites you, next to who shows up instead. The question queries from pattern 1 make a sensible first batch, and you can try Slibur free for 7 days, no card required.

Frequently asked questions

Does Google Search Console support regex?

Yes. In the Performance report, add a Queries or Pages filter, choose Custom (regex), then pick Matches regex or Doesn't match regex. It uses RE2 syntax, matches any part of the query or URL, and ignores case unless the pattern starts with (?-i). Lookahead, lookbehind and backreferences are not supported.

Is GA4 regex case-sensitive?

Yes. GA4 regex is case-sensitive, and with the "matches regex" condition it has to match the whole value. Use "matches partial regex" for a contains-style match, or add .* on both sides of the pattern. In report filters, each regex is limited to 250 characters.

Why won't Search Console accept my regex?

Usually because the pattern uses something RE2 doesn't support, most often a lookahead such as (?!...), which AI assistants like to write. Rewrite it as two conditions, one that matches and one that doesn't, and check for unescaped brackets or parentheses.

Can I use regex in robots.txt?

No. Google supports only two wildcards in robots.txt paths: * for any sequence of characters and $ for the end of the URL. Everything else, dots and question marks included, is read literally, and matching is case-sensitive.

What regex does Screaming Frog use?

The Java regex library. Unlike RE2 it accepts lookarounds, and it tests the URL-encoded address, so escape a question mark as \? and write a pipe inside a URL as %7C. Wrapping a full URL in \Q and \E makes every character literal.

How do I filter out branded queries with regex?

In Search Console, add a Queries filter with Custom (regex), choose Doesn't match regex and enter your brand with its misspellings, such as \b(acme|acmee|akme)\b. Eligible top-level properties can use the built-in branded queries filter instead, which Google sorts with an AI-assisted system.

What is the difference between REGEXP_MATCH and REGEXP_CONTAINS?

In Data Studio, formerly Looker Studio, REGEXP_MATCH is true only when the pattern matches the entire value, while REGEXP_CONTAINS is true when it matches any part of it. REGEXP_CONTAINS(field, "pattern") behaves like REGEXP_MATCH(field, ".*pattern.*").

About the author

Founder of Slibur

Raúl Díaz is the founder of Slibur, the tool that asks ChatGPT, Google AI Overviews, Claude, Perplexity and Grok the questions your customers ask and shows which brands they recommend. He writes about answer engine optimization from the data Slibur collects.

  • Analytics

    Direct Traffic and SEO: What GA4 Counts as Direct and Why It Rises

    Direct traffic is the GA4 channel for visits that arrive with no referrer and no campaign tags, labeled (direct) / (none). For SEO it is not a ranking signal: Google has said it doesn't use Analytics data in Search. It still matters, because organic visits that lose their referrer are counted there.

    11 min read

  • AI crawlers

    Python for SEO: 6 Short Scripts for Sitemaps, Canonicals, Search Console and AI Crawlers

    Python for SEO is a set of scripts that take over the checks you repeat every week: listing the URLs in a sitemap, testing status codes and canonical tags, joining that crawl with Search Console data, grouping queries, and reading robots.txt the way GPTBot or ClaudeBot does. The six scripts below need only the Python standard library.

    12 min read

  • AI visibility

    Dealer SEO in 2026: Local, Inventory and AI Search

    Dealer SEO is the work of making a car dealership easy to find in search: a complete Google Business Profile, inventory pages Google can index, useful local content and clean measurement. In 2026 it also includes how AI assistants describe your store when a buyer asks where to shop.

    12 min read