Regular expressions, or regex, are short text patterns that match many strings at once, such as every page address starting with /blog/ or every search that contains “near me”, so you can filter reports and rules in one step instead of one line at a time. MDN defines them simply as patterns used to match combinations of characters in strings. In SEO and analytics they turn a list of thousands of rows into the handful you care about.
What is a regular expression? #
A regex is ordinary text mixed with a few special characters, called metacharacters, that stand for “any character”, “one or more” or “either this or that”. The pattern blue|navy matches any text containing blue or navy. The pattern ^/shop/ matches any address that begins with /shop/. You write the pattern once and the tool tests it against every row.
Regex is not one single language. Each tool uses a flavour. Google Search Console points to the rules of Google’s RE2 engine, JavaScript uses its own, and a server’s rewrite rules may use another. The basics below work almost everywhere.
The characters you will use most #
Google’s Analytics help page on regular expressions lists these:
| Character | Meaning | Example |
|---|---|---|
| . | Any single character | s.t matches sat, set and sit |
| * | The character before, 0 or more times | go*gle matches ggle, gogle and google |
| + | The character before, 1 or more times | 10+ matches 10, 100 and 1000 |
| ? | The character before, 0 or 1 times | https? matches http and https |
| | | Or | london|leeds |
| ^ | Start of the text | ^/blog/ |
| $ | End of the text | \.pdf$ |
| ( ) | Group parts together | (red|blue) dress |
| [ ] | Any one of these characters | [0-9] for one digit |
| \ | Treat the next character as plain text | \. for a real full stop |
MDN’s regular expressions guide gives the same escaping rule: to search for a special character itself, such as a star, put a backslash in front of it.
Why does regex matter for search? #
Search data comes in long lists of queries and pages. Regex lets you slice them by meaning. In the Search Console performance report you can choose Custom (regex) in the filter, and Google’s Search Central blog said in June 2021 that the report supports both “matches regex” and “doesn’t match regex”. The same post points to the RE2 syntax reference for what is allowed. Useful filters include:
- Brand vs non-brand. A “doesn’t match” filter on your brand name and its typos shows non-brand searches only. See branded keyword.
- Site sections. ^https://example\.com/(blog|guides)/ groups content pages away from product pages.
- Local intent. near me|nearby|open now finds local searches.
- Long questions. A pattern such as ^(\S+\s){6,} catches queries of 7 words or more, a rough view of the long tail.
Why does regex matter for AI answers? #
AI visibility work is mostly pattern matching on messy data. In server logs, a pattern on the user agent such as GPTBot|ClaudeBot|PerplexityBot pulls out AI crawler visits from millions of lines; see GPTBot and ClaudeBot. In analytics, a referrer pattern such as chatgpt\.com|perplexity\.ai|copilot\.microsoft\.com groups AI referral traffic into one channel. Remember that a user agent can be faked, so pair any pattern with a check such as our bot verifier. Our AI crawler log analyser does the log matching for you.
How does RE2 differ from other flavours? #
The RE2 syntax page marks lookahead, lookbehind and backreferences as not supported. So patterns copied from coding forums that use (?= or \1 will fail in Google’s tools. RE2 does support flags in the form (?i), which turns on case-insensitive matching. Google’s Analytics help page says its regex is case sensitive and a full match by default: plain text with no metacharacters only matches values that are exactly the same, and you add .* for a partial match. For example, .*London.* matches “London” and “North London”, while London on its own matches only “London”.
Where else will you meet regex? #
- Google Analytics 4 filters, audiences and channel rules.
- Google Tag Manager triggers that fire on matching pages.
- Looker Studio calculated fields and filters.
- Server rewrite and redirect rules, for example in an .htaccess file.
- Crawlers and scripts, such as Python for SEO.
One trap: robots.txt is not regex. Google’s robots.txt guide describes only a limited form of wildcards: * for 0 or more of any character and $ for the end of the address. Paths there are case sensitive. Check yours with our robots.txt checker.
Common mistakes #
- Forgetting to escape the full stop. example.com also matches exampleXcom. Write example\.com.
- Ending with a stray pipe. red|blue| matches everything, because the last option is empty. Google’s Analytics help page warns against a pipe at the end.
- Case surprises. /Blog/ and /blog/ are different unless you add (?i) where the tool supports it.
- Patterns that are too greedy. .* at both ends can match far more than you meant. Test on real rows first.
- Using unsupported features such as lookahead in RE2 tools.
A worked example #
A florist wants clicks from non-brand searches about weddings. In Search Console it picks Query, then Custom (regex), then “doesn’t match”, and enters (?i)bloom ?and ?stem to remove its brand, Bloom and Stem, with or without spaces. It adds a second Query filter, Custom (regex), “matches”, with (?i)wedding|bridal|buttonhole. The table now shows only non-brand wedding searches. It saves the patterns in a note, so the same view can be repeated each month and compared.
How to check it #
- Write and test every pattern in our regex tester against a few real rows before you use it in a report.
- Check the row count makes sense. If a filter returns everything or nothing, look for a stray pipe or a missing escape.
- Check your analytics tags are firing with our tracking checker, so the data you filter is complete.
- To keep these splits without retyping them, two URSY Pro reports are being built: page groups (Pro) and branded vs non-branded (Pro).
Questions #
Do I need to learn to code to use regex? #
No. The 10 characters in the table above cover most SEO and analytics filters.
Is regex case sensitive? #
Often yes, including in Google Analytics. In RE2 tools you can add (?i) at the start to ignore case.
Why does my pattern from a forum not work in Search Console? #
It may use lookahead, lookbehind or a backreference, which RE2 does not support.
Related words #
- Search Console performance report
- Log file analysis
- Audience segmentation
- Analytics data quality
- URL parameter
Sources #
- MDN Web Docs: Regular expressions, checked 25 November 2026
- Google Analytics Help: About regular expressions, checked 25 November 2026
- Google RE2: Syntax, checked 25 November 2026
- Google Search Central Blog: regex filter tips, 2 June 2021, checked 25 November 2026
- Google Search Central: How Google interprets the robots.txt specification, checked 25 November 2026
Updated 25 November 2026 by URSY.
Cite this page: Regular expressions (regex). URSY. Updated 25 November 2026. https://ursy.com/wiki/regular-expressions-regex/ · Section links
Tools for this
- LiveAI Readiness Checkeris your site ready for ChatGPT, Gemini, Claude? Score + fixesRun the check →
- LiveAI Bot Checkerwhich AI bots your robots.txt lets inRun the check →
- LiveRobots.txt Checker + Generatortest any address against your rules, or write new onesRun the check →
- LiveSchema Markup CheckerRun the check →