Tools & Platforms

Regular Expressions (Regex)

In shortA compact pattern language for finding, matching and extracting text, used in Search Console filters, Google Sheets, GA4 and Python.

Updated 24 Oct 2026· 2 min read

A regular expression, or regex, is a pattern that describes a set of text strings. Instead of searching for one exact word, you can match “any query that starts with how, what or why”, “any URL in the /blog/ folder” or “any keyword that contains a brand name or a common misspelling of it”. Regex involves no machine learning. It is still one of the most useful tools for preparing data and building rule-based classifiers in SEO.

How it works

A pattern combines literal characters with special symbols:

  • | means “or”: buy|price|cheap matches any of the three.
  • ^ and $ anchor the start and end: ^how matches queries that begin with “how”.
  • . matches any character; *, + and ? control repetition; \b marks a word boundary.
  • (?i) makes a pattern case-insensitive in RE2-based tools; brackets group parts of a pattern.

Different tools use slightly different regex flavours. Google Search Console, Google Sheets (REGEXMATCH, REGEXEXTRACT, REGEXREPLACE) and Looker Studio use Google’s RE2 syntax, which does not support lookaheads. Python’s re module supports more features.

How it’s used in SEO and marketing

  • Search Console filters: isolating question queries, branded versus non-branded queries, or a site section.
  • Rule-based search intent classification: one pattern per intent or micro intent (“how to fix”, “near me”, “vs”).
  • Keyword categorisation: flagging brand, competitor, product or location terms in a keyword universe.
  • Crawling: Screaming Frog custom extraction and include/exclude rules.
  • Cleaning: stripping parameters, emails or boilerplate from URLs and text.

Example

To find question queries in Search Console, use a custom regex filter on queries such as ^(who|what|why|when|where|how|which|can|does|is)\b. To label branded keywords in Google Sheets, use =REGEXMATCH(A2, "(?i)mlforseo|ml for seo|ml4seo"), adding common misspellings over time. MLforSEO’s lessons also suggest asking an LLM to draft a brand regex from a list of keywords, then checking it by hand.

Limitations and things to watch

  • Regex matches characters, not meaning. It will miss paraphrases and synonyms you did not list, which is where fuzzy and semantic matching help.
  • Patterns can over-match: “art” also matches “start” unless you add word boundaries.
  • Keep patterns readable and documented, and refresh them as new queries and products appear.
  • Test on a sample before applying a pattern to a full data set.

Learn it on MLforSEO

Where Regular Expressions (Regex) shows up on MLforSEO

Sources and further reading

Other terms from Tools & Platforms

See all 25 Tools & Platforms terms →