regex for seo

Regular expressions are a game-changer for SEOs who know how to use them. Recently, I have started using them more with the help of ChatGPT.

This article is a guide for non-technical SEOs to up their game with a combination of Regex templates and using AI.

How to Use This Guide

In some cases, you only need to copy & paste the regular expressions in Google’s Search Console:

Custom regex in GSC

In other cases, you need to make a list of the specific keywords you need. If you can’t change the regular expressions yourself, use ChatGPT and give it the instructions for the regex.

Create a question regex with chatgpt

*ChatGPT’s free version of 3.5 is enough, no need to upgrade.

**You might need to specify a second time that the regex should work on GSC or try a couple of variations to work.

Brand Searches

This is my favourite regex to use. It can easily split your queries into branded and non-branded keywords.

This allows you to view the brand lifts of events or seasonal drops.

Let’s take an example of a big brand like Microsoft, the brand query would look something like this:

.*Microsoft.*|Micro*soft.*|micros.*|m*soft.*

How to create a Brand Regex for GSC with ChatGPT

  • Use your homepage as a filter.
  • Export all the keywords from the GSC.
  • Sort them by the search volume.
  • Filter the branded keywords & misspellings.
  • Feed them to ChatGPT.
Microsoft misspellings to create a regex in chatgpt

I used 20 misspellings of Microsoft to do this, your regex will probably look different.

Branded vs Non-Branded

Remember to use “Matches regex” for the branded term.

Using “Doesn’t match regex” will give you the non-branded terms.

showing how to add a regex in the GSC

Short-Tail or Long-Tail Queries

Do you want to target long-tail queries and opportunities?

You can always use regex to filter your GSC keywords into long-tail and short-tail.

Use this regex for long-tail queries of 8 words or more:

([^” “]*\s){7,}?

Or, this one for short-tail queries of 1-4 words:

^(?:\b\w+\b\s*){1,4}$

You can change the numbers to find longer or shorter queries!

Questions

Are you looking for ideas for articles?

Your GSC might have the answer … or the question, with question queries you might be ranking in the second and third pages.

There is an easy way to find all the question queries in your GSC, and that’s the following regular expression:

^(Who|What|When|Where|Why|How|Can|Do|Is|Are)\b

Just copy and paste it!

Longer questions

Short questions are usually more difficult to rank for. You can customise the regex to bring the long-tail questions only:

^(Who|What|When|Where|Why|How|Can|Do|Is|Are)\b(?:\W+\w+){7,}

The above regex will bring questions of 8 words or more.

Find Keyword Groupings

Commercial Queries

If you want to export all the commercial queries from GSC or look at them as a group, you can use this regex:

.*(best|top|alternate|alternative|vs|versus|review*).*

This will group the queries that include:

  • Best
  • Top
  • Alternate
  • Alternative
  • Vs
  • Versus
  • Review

You can change the words and replace any with another one, or add more by using | and then writing the word.

Or, you can feed ChatGPT your commercial queries and ask it to create a Regex for GSC that will match those and similar ones for you..

Product IDs or SKUs

Let’s say you want to view the performance of an ecommerce store, a specific series of products, or multiple products.

The products may be in multiple URLs and their IDs or SKUs look like these:

  • A123
  • A999
  • A235
  • PR097
  • PR278
  • ABC234
  • ABC 987
  • ABC091

I asked ChatGPT to write the regex to find these and similar product pages with different numbers.

^(A\d{3}|PR\d{3}|ABC\d{3}|ABC\s?\d{3})$

This regex is to be used in the page filters.

Other Groups

You can do the same as above to group searches or pages that are related in any way you like. Here are a few ideas:

  • Colours: Red, green, blue, yellow
  • Clothing items: Shoes, t-shirts, pants
  • Categories: Guides, How-tos, Templates

Misspellings

Misspellings are done similarly to Brand searches but for non-branded keywords.

Collect all the misspellings you can find in your search console or ask ChatGPT for possible misspellings of a specific word. Then, ask it to create a regex that can find all those misspellings.

AGo6z5rmxkJIL90oe Znq0GSKuFYNSw2h2pR2hQ6SGnIAzmeHwyD4v8gPTr fNZXVqNw5bRwKUCXGf8AwUbYD4UW2ITmXzBGyE2VDtbX6ryEPcwsjwx5iz 8b8ZHjfzeuib1ERmi38Qb1CeMUBMoLI

Let’s Make Some SEO Magic

These are only a few of the possibilities where you can use regular expressions to filter queries through Google’s Search Console.

If you want to learn more about Regex for SEO, I suggest the following articles which helped with some ideas while writing the article, and are a good beginner’s guide on Regex: 

And, if you want to take your knowledge to the next level, I do suggest taking a look at LearnSEO.io. It also has a dedicated section on Regex!