Deutsch
Search Console

Regular expressions (regex)

Also known as: regex, regexp, regular expression

A regular expression (regex) is a text pattern that describes a set of strings. A tool compares the pattern with a text and reports whether and where it matches. In SEO, regex is mainly used to filter or group URLs and search queries in tools such as Search Console, Google Analytics, Looker Studio and crawlers.

How do regular expressions work?

A pattern combines literal characters with special symbols. The most useful ones in RE2, the engine developed by Google, are:

Symbol Meaning
. any single character
* + ? zero or more, one or more, zero or one of the preceding item
^ $ start and end of the text
[abc] one character from the set
(a|b) a or b
\d \w a digit, a word character
{n,m} between n and m repetitions

Characters like . ? ( and | have a special meaning. A literal dot needs a backslash (\.). RE2 does not support backreferences and lookahead or lookbehind, so patterns copied from other languages may fail. The Search Console API names RE2 syntax for its regex filter operators (includingRegex, excludingRegex), and the filter in the interface reportedly uses it as well.

Example

Filtering URLs for all blog posts from 2025 or 2026:

Code
^https://example\.com/blog/(2025|2026)/.+

Filtering queries that contain a brand name in two spellings:

Code
(acme ?shop|acmeshop)

Common mistakes

  • Unescaped dot. example.com also matches exampleXcom.
  • Missing anchors. Without ^ and $, a pattern matches anywhere inside the text.
  • Patterns from other languages. Lookahead works in JavaScript and not in RE2.
  • Case sensitivity. Check whether the tool treats Shoes and shoes alike. With RE2, the flag (?i) switches case-insensitive matching on.

Sources

  1. RE2 Syntax – GitHub google/re2 wikigithub.com
  2. Regular expressions – JavaScript – MDN Web Docsdeveloper.mozilla.org
  3. Regular-Expressions.inforegular-expressions.info
  4. Search Analytics: query – Search Console API (includingRegex, excludingRegex)developers.google.com

Last updated: