Search Console regex cookbook

Reusable RE2 patterns for brand queries, directories, product URLs, questions, and intent groups.

Derived analysis Automatable now Intermediate

Search Console uses RE2 regular expressions for custom Query and Page filters. Matching is partial and case-insensitive by default. Add ^ and $ when the entire value or a boundary matters, and prefix the expression with (?-i) only when case must be respected.

Replace the example brand, domain, folders, locales, and product syntax before using these recipes. Test the pattern against known matching and non-matching rows, then inspect the generated total: any query filter removes anonymized queries from the filtered data.

Essential syntax

Pattern Meaning Example
. Any single character c.t matches cat and cot
\d A digit sku-\d+ matches sku-123
\s Whitespace search\sconsole
[abc] One listed character gr[ae]y
[^/] One character except / Useful inside one URL segment
* Previous item zero or more times seo.*audit
+ Previous item one or more times \d+
? Previous item zero or one time https? matches http or https
(?:...) Non-capturing group `(?:blog
` ` OR
^ Start of target ^how
$ End of target \.pdf$
\b Word boundary \bseo\b avoids matching museum
\. Literal period example\.com
\? Literal question mark Useful for URL query strings

RE2 deliberately does not support lookahead, lookbehind, or backreferences such as (?!...), (?<=...), or \1. Use Search Console's Doesn't match regex control for exclusions, stack simple include/exclude filters where supported, or filter exported data downstream.

Query recipes

Brand-name family

\b(?:acme|acme corp|acmecorp)\b

Use for a transparent rule-based brand segment. Add common product names and misspellings only when they uniquely identify the brand. This will not necessarily match Google's AI-assisted branded-query classification.

Query begins with the brand

^(?:acme|acme corp)\b

Useful for navigational searches while excluding queries that mention the brand later in a comparison or review.

Non-brand segment

Apply Doesn't match regex to the brand-family pattern. Document that hidden queries are excluded from both the matching and non-matching filtered views, so the two totals need not sum to the unfiltered chart.

Question queries

^(?:who|what|when|where|why|how|can|could|do|does|is|are|should|which)\b

Add question forms for the languages actually used by the audience. This identifies phrasing, not intent with certainty.

Commercial investigation

\b(?:best|review|reviews|compare|comparison|vs\.?|versus|alternative|alternatives)\b

Transactional language

\b(?:buy|price|pricing|cost|discount|coupon|deal|quote|demo|trial)\b

Support and troubleshooting

\b(?:error|issue|problem|fix|broken|not working|troubleshoot|support)\b

Local-intent terms

\b(?:near me|nearby|in madrid|in barcelona|madrid|barcelona)\b

Location words are directional evidence, not proof of local intent. Cross-check the Country dimension and landing pages.

Version or model numbers

\b(?:v|version\s*)?\d+(?:\.\d+){0,2}\b

This finds integers and dotted versions and can overmatch years or prices. Narrow it with a product term when possible.

Exact query family

^(?:google search console|search console|gsc)$

Anchoring both ends prevents unrelated longer phrases from matching.

URL recipes

Examples assume canonical HTTPS URLs on www.example.com. If the property contains multiple protocols or hosts, deliberately broaden the prefix.

Exact homepage

^https://www\.example\.com/$

One directory and all descendants

^https://www\.example\.com/blog(?:/|$)

The (?:/|$) boundary prevents /blogger/ from matching.

Several content directories

^https://www\.example\.com/(?:blog|guides|resources)(?:/|$)

Any protocol and optional www

^https?://(?:www\.)?example\.com/(?:blog|guides)(?:/|$)

Use this only when the selected property legitimately contains those variants. Performance is normally attributed to the canonical URL, so duplicate variants may not appear as separate rows.

Locale folders

^https://www\.example\.com/(?:en|es|fr)(?:/|$)

First-level folder only

^https://www\.example\.com/[^/]+/?$

This matches a single path segment, not its descendants.

Product detail URLs with numeric IDs

/products/[0-9]+(?:[/?]|$)

Product category pagination

/category/[^/?]+(?:/|\?[^#]*\bpage=[0-9]+)

Use a Page filter only if parameterized URLs are actually present in the credited Performance rows.

File extensions

\.(?:pdf|docx?|xlsx?|pptx?)(?:\?|$)

URLs containing query parameters

\?

This is broad. For a specific parameter use:

[?&]utm_source=

Trailing-slash URLs

/$

Date-based archive paths

/20[0-9]{2}/(?:0[1-9]|1[0-2])(?:/|$)

Apply Doesn't match regex to:

/(?:staging|preview|search)(?:/|\?|$)

Useful combined workflows

Brand versus non-brand

  1. Define one reviewed brand-family expression.
  2. Save the unfiltered chart total for context.
  3. Apply Matches regex for the rule-based brand view.
  4. Apply Doesn't match regex for the rule-based non-brand view.
  5. Do not claim the filtered totals reconstruct all queries; privacy-filtered queries disappear after query filtering.

Directory performance without similarly named folders

Prefer:

^https://www\.example\.com/blog(?:/|$)

over:

/blog

The second also matches /blogger, /old-blog, and query-string values containing the text.

Include a topic but exclude jobs

Use a positive query pattern such as:

\bsearch console\b

and a negative filter such as:

\b(?:job|jobs|career|careers|salary)\b

Do not attempt a negative lookahead; RE2 does not support it.

API notes

The Search Analytics API provides includingRegex and excludingRegex filter operators. Filters inside the supported and group must all match. The maximum filter expression length is 4,096 characters, but long generated patterns are difficult to review and can create expensive page/query requests. Split durable business groupings into maintained configuration rather than embedding an unreadable expression in every request.

Regex behavior is for matching dimension strings; it does not change Google's query classification, crawl handling, canonical choice, or rankings.

Common mistakes

  • Forgetting that . means any character; escape literal dots in domains.
  • Using an unanchored folder name and matching unrelated paths.
  • Copying a PCRE lookaround or backreference into RE2.
  • Adding spaces around | and unintentionally requiring those spaces.
  • Treating regex groups as a complete intent classifier.
  • Comparing a filtered query total with an unfiltered total without accounting for anonymized queries.
  • Testing against decoded URLs while Search Console displays an encoded form.
  • Assuming a URL regex can reveal duplicate URLs whose data was consolidated to the canonical.

Validation checklist

Before reusing a pattern, maintain at least five expected matches and five expected non-matches. Check boundaries, singular/plural terms, punctuation, encoded URLs, and multilingual variants. After applying it, sample the highest-impression rows and revise obvious false positives before using the segment in reporting.

Official sources