• AI Bootcamp
  • Marketingová Plzeň
  • SEO Pivo
  • Contact
  • [email protected]
  • Personal website
[email protected]
Personal website
SEO, AI and Marketing Blog
Martin Bangho
  • Home
  • GEO & SEO
  • AI
  • Marketing
  • CS
  • EN
  • Home
  • GEO & SEO
  • AI
  • Marketing
  • CS
  • EN
Home GEO & SEO
Muž v bílé košili přikládá modrý kotouč ke kruhovému otvoru šablony.

RegEx for SEO: filters for Search Console and GA4

Martin Bangho by Martin Bangho
November 24, 2026
in GEO & SEO
Reading Time: 6 mins read
0
0

RegEx, or a regular expression, is a pattern for searching text. In SEO, it is useful for selecting a group of queries, filtering URLs or dividing an export into manageable sections. But an expression cannot understand a page’s meaning or determine search volume or purchase intent on its own. First, you need to know what the filter should include and what it must exclude.

Start with a rule, not a collection of characters

“I want to select categories” is not a sufficient brief. Categories are a content type, while regex sees only a text string. If some categories have one URL level and others have two, a single pattern based on the number of slashes will not identify them. First describe the data structure, or use a page-type map from the CMS.

A good brief might be: “In an export of full URLs, select addresses on example.com with two nonempty path levels and an optional trailing slash, but no query parameters or fragment.” Now you can determine which rows should pass. For every task, write down several positive and negative examples beforehand. Negative cases reveal the error that a nice match on the first row can hide.

Further reading

Muž v bílé košili měří dřevěný hranol posuvným měřidlem.

SEO tools: choose a toolkit for your work and budget

November 24, 2026
Muž připíná prázdné papírové bubliny na korkovou nástěnku.

Google AI Mode: how it works and what it means for your website

November 24, 2026
Muž v bílé košili zkoumá bílou kostku lupou u pracovního stolu.

GEO and AEO myths: how to recognise evidence-backed advice

November 24, 2026
Muž vkládá žlutou kartičku do barevné kapsy na nástěnce.

Keyword Research: From Queries to a Page Map

November 24, 2026

If you are looking for a single fixed substring, a plain “contains” filter may be clearer. Regex is worthwhile when you need alternatives, boundaries or a variable part. A more complicated expression does not automatically make a better analysis.

Search Console and GA4 do not share the same defaults

In Search Console, the custom regex filter uses RE2 syntax. Matching is partial and case-insensitive by default. The expression seo can therefore also select the query SEO audit or jak na seo. If you need the entire string, add suitable anchors. The documentation specifies the (?-i) flag for enforcing case sensitivity.

Google Analytics, by contrast, documents full, case-sensitive matching by default. In that mode, the expression seo alone will not select jak na seo or SEO. Always check the operator and field for the specific condition you are using. The difference between full matching and searching within text can change an entire report without producing a syntax error.

RE2 also cannot do everything you may know from PCRE or another regex tester. For example, it does not support lookahead, lookbehind or backreferences in a pattern. If you need to exclude something in Search Console, use the “Doesn’t match regex” option where appropriate, rather than copying a negative lookahead from a guide for another system. The RE2 syntax reference lists supported constructs.

A few characters you really need to understand

The vertical bar | separates alternatives, and parentheses group them. The expression ^(seo|geo)$ selects the entire string seo or geo. A different expression, ^seo|geo$, also selects seo audit and seznam geo during partial searching: the first branch is anchored only at the beginning, the second only at the end. Parentheses are not cosmetic.

The dot . is a wildcard, not automatically a literal dot. In a domain name, use example\.com, for example, if you want to match the dot itself. The asterisk * repeats the preceding item zero or more times; the plus + repeats it one or more times. The expression .* is a broad match; there is no need to stick it before and after every expression, especially in a tool that uses partial searching.

Square brackets create a character class. The expression [^/?#]+ below means one or more characters other than a slash, question mark or hash. A caret inside this class negates its contents; at the start of the whole pattern, it has a different meaning: a start anchor. The same character therefore depends on where it is used.

An illustrative filter for Czech branded queries

For the fictional brand “Modrá dílna”, we also want to include the spelling without diacritics, but not strings where the name is embedded in another word. The following pattern is intended for partial searching in RE2, for example on queries in Search Console. Its (?i) flag explicitly enables case-insensitive matching:

(?i)(^|[^\p{L}\p{N}_])(modrá dílna|modra dilna)([^\p{L}\p{N}_]|$)

\p{L} stands for Unicode letters and \p{N} for numbers; here, we treat an underscore as part of a word. The expression therefore checks the name’s boundary even with Czech letters. In RE2, \b uses ASCII word boundaries, so the simple pattern \bčaj\b will not even find the standalone string čaj. For Czech data, it is unsafe to assume that every word shorthand handles diacritics as a person would.

  • Examples that should pass include Modrá dílna kontakt, recenze modra dilna and (modrá dílna).
  • xmodrá dílna, modra dilna2 and modra dilnař will not pass because the required boundary is missing.
  • The variant modrá dílna.cz passes: the dot matches the defined separator. If you do not want this, you must change both the brief and the test.

This is an illustrative vocabulary, not a ready-made filter for your company. Add misspellings and product names only if you actually want to include them. A generic name may also have a nonbranded meaning; regex cannot distinguish it by context. Nonbranded queries obtained by inverting the filter therefore still do not form a perfectly clean business category.

Selecting URLs with two path levels

For the precise brief above, we will use the following RE2 pattern. The domain is illustrative, the input is the full URL, and matching is case-sensitive. In Search Console, the initial (?-i) explicitly enables that here:

(?-i)^https://example\.com/[^/?#]+/[^/?#]+/?$

https://example.com/boty/zimni/ and the same URL without the final slash will pass. A single level, /boty/, a third level, /boty/zimni/model/, and a URL with ?sort=cena or #detail will not. The escaped dot and anchored beginning also prevent matching the domain exampleXcom or example.com.evil.test.

The expression deliberately rejects query parameters and fragments. If your export contains them and you want to keep them, change the rule rather than adjusting your interpretation afterwards. Normalise data separately and retain the original column. Above all, two path levels do not prove that a URL is a category. They are merely a property of the URL.

A full match for source and medium in GA4

If you want to select exactly two values in the session source / medium field, google / organic and bing / organic, you can use this full-match expression:

^(google|bing) / organic$

An illustrative test accepts both specified values. It rejects google / cpc, notgoogle / organic, google / organic extra and, with case sensitivity enabled, Google / organic too. Spaces around the slash also matter. Before using it, check your field’s actual values and make sure you are working at session scope, not user scope.

This selection does not cover “all organic traffic”. It includes only the two specified values and may exclude other search engines. If the goal is the Organic Search channel, consider whether the corresponding channel dimension would be more suitable. The filter must fit the decision, not just a familiar example from the internet.

How the examples were verified, and what you need to verify

The main patterns shown and their accompanying counterexamples were tested against synthetic strings using the actual Google RE2 library through its Python binding. The test distinguished partial searching from full matching and checked case-sensitivity settings. For the URL pattern, it also verified the flag included directly in the example. This was not a run in an authenticated Search Console or GA4 account, nor a test on customer data.

This kind of check verifies syntax and expected behaviour on the supplied examples. It does not prove that your field contains the same values or that you have defined the segment correctly. When implementing a filter, compare samples of both included and excluded rows, and the report’s scope before and after filtering. Search Console also warns that filtering queries and URLs can affect totals because of data truncation and the omission of anonymised queries. A mismatch in totals therefore does not automatically mean a faulty regex.

If you ask AI to suggest an expression, specify the tool, dialect, input field, matching mode and positive and negative examples. Then review it just as you would your own expression. Do not send real private queries, tokens or personal data to public testers without assessing the risks. A synthetic example with the same structure is usually enough to share a bug.

Save the rule alongside the report

Alongside the pattern, keep its purpose, dialect, mode, verification date and a small test set. When URLs or the brand name change, update the tests too. Do not transfer a regex used to filter an analytics export into redirects, deletion or bulk data replacement without further review: the same error can have much more serious consequences there.

For a first attempt, take a small anonymised export and one clear rule. If you use the filter to inform content decisions, follow through with a content strategy as well: correctly selected rows are the start of an analysis, not a finished priority list for the entire website.

Need to select the right data from your exports?

I can help you define a segment and check whether the filter matches the question you want the data to answer. Let’s discuss your report brief. For an initial conversation, a description of the tool, field and rule is enough; we will transfer private data only through an agreed channel.

Tags: GuideTools
Previous Post

Canonicalisation and pagination: how to use canonical correctly

Next Post

International SEO: from choosing a market to hreflang

Martin Bangho

Martin Bangho

I’m Martin Bangho. I’ve worked in digital marketing and built websites since 2015. These days I help companies with SEO and with getting found in AI search. I question things, and I’m picky about the details, but I’m an optimist. I believe marketing can be honest and still make money for a business. When I’m not working on marketing or running my business, you’ll probably find me at the gym, at a hip-hop gig or out with friends. On this blog I write about questions that come up with clients, what I test myself and what I make of the results. Hermes, my AI assistant, helps me write. I bring the notes, the results and my own take. Hermes helps me structure the article, catch grammar mistakes and get back to the point when I’ve gone off on my third tangent in the middle of a sentence. I review and edit every article myself before it goes out, so it says exactly what I mean.

Related articles

Martin Bangho in a white shirt examines two sheets with blue and grey website layouts using a magnifying glass at a wooden desk.
GEO & SEO

Buying a website: how much of its organic traffic is valuable to you?

November 25, 2026
Martin Bangho compares blue and sand-coloured folding-chair models with their matching photo cards.
GEO & SEO

Visual discoverability: connecting images to the right product and location

November 25, 2026
Jak vybrat copywritera?
GEO & SEO

How to Choose a Copywriter

November 24, 2026
SEO GAP Analýza
GEO & SEO

SEO GAP Analysis

November 24, 2026
Next Post
Muž v modré košili drží dvě barevné desky se stejným motivem domečku.

International SEO: from choosing a market to hreflang

Odebírat
Upozornit na
0 Komentáře
Nejstarší
Nejnovější Nejlépe hodnocené

Martin Bangho

SEO Consultant & AI Strategist

I use data to build marketing plans with people across a business, from sales and development to content. The aim is to strengthen the brand and help it compete.

Tags

Analysis B2B B2C Brand E-commerce Event reports Google Guide Hermes Off-page SEO On-page SEO SaaS Technical SEO Theory Tools User Experience Websites

Latest posts

  • Buying a website: how much of its organic traffic is valuable to you?
  • Visual discoverability: connecting images to the right product and location
  • How to Choose a Copywriter
  • SEO GAP Analysis
  • How to Create a Content Calendar
  • Home
  • GEO & SEO
  • AI
  • Marketing
  • CS
  • EN

© 2025 Martin Bangho – SEO Consultant & AI Strategist

Welcome Back!

Login to your account below

Forgotten Password?

Retrieve your password

Please enter your username or email address to reset your password.

Log In
  • Home
  • GEO & SEO
  • AI
  • Marketing
  • CS
  • EN
[email protected]

© 2025 Martin Bangho – SEO Consultant & AI Strategist

This website uses cookies. By continuing to use it, you agree to their use. Read our privacy and cookie policy (in Czech).