Stop Using Regex—You’re Wasting Your Time

Stop Using Regex—You’re Wasting Your Time

Gotcha! ?? If you’ve been skipping regex thinking it’s not worth the effort, let me show you why it’s actually a game-changer.

And if you’re still not convinced by the end, well, I’ll probably just lose 10 minutes of your time. But you’ll never know until you start reading! ??♂?

What the heck is Regex?

Most people have heard of regex (regular expressions), but what exactly is it?

A regex is a sequence of characters that defines a search pattern. It's a powerful tool used in search engines, computer programs, and more to streamline 'find' or 'find and replace' operations.

If you’re using Google Search Console, you can apply RE2 to analyze your URLs, keyword groups, and topics. This way, you can quickly identify optimization opportunities, content gaps, and areas for further analysis.

But let’s be real—regex can be a bit confusing.

The syntax isn’t easy to memorize, and mistakes happen.

That’s why I’ve put together this guide as your go-to cheatsheet for mastering regex and unlocking its full potential. Don’t let the complexity scare you off. Dive in, and you’ll be amazed at what you can achieve!

Implementing basic filters before introducing regex filters is a strategic approach:

How to Apply Regex in Google Search Console

Applying a regular expression (regex) filter in Google Search Console is a powerful way to refine your data analysis. But before you dive in, there are a few things you need to know:

First, Google Search Console uses RE2, which means not all regex patterns are supported.

Pro tip: Always start with some basic filtering before applying regex.

Here’s how to do it:

  1. Open Google Search Console
  2. Click “Performance”
  3. Click “New”
  4. Click “Country”
  5. Select “YOUR COUNTRY” from the list
  6. Click “Apply”

(You might also want to filter the dates to the most recent ‘28 days’ and optionally filter by device: Smartphone or Desktop)

Once you’ve applied the basic filters, you’re ready to add a regex filter:

  1. Open Google Search Console
  2. Click “Performance”
  3. Click “New”
  4. Click “Query” or “Page”
  5. Select “Custom Regex” from the dropdown

Bonus Tip: Click on the Export option in the top right corner to export your filtered data for further analysis.

Master these steps, and regex in Google Search Console will become a game-changer for your SEO strategy.

Understanding Regex Metacharacters

Here are some of the most useful regex expressions. But there’s more where that came from. For a deeper dive, check out this cheatsheet.


Query-Specific Regex:

This list is just the beginning of what you can do with Regex. I believe you'll find yourself reaching for them just as often in your own work.

1.???? Identifying Queries by Word Count: Quickly filter queries by their word count to target long-tail keywords or specific query lengths.

([^\s]*\s){5,}        

Example: Searches for queries containing more than five words, a common criterion for identifying more specific user intents (ideal for finding long-tail keywords).

Note: Regex is zero-indexed. Meaning that if you use 5 you are actually searching for queries with six or more words.

2.???? Capturing Queries Containing Questions: Use the OR operator to find queries that likely represent questions.

who|what|where|when|why|how|was|did|do|is|are|does|if|can|could|should|would|were        

Example: This pattern detects any queries incorporating common question words, regardless of their position within the query.

You can add more words to the string above so long as you use the separator. Equally, you can use fewer words to bring back more specific queries.

3.???? Filtering Questions at the Start of Queries: Narrow down to queries where the question begins the query, indicating a direct question.

^(who|what|where|when|why|how|was|did|do|is|are|does|if|can|could|should|would|were)        

Example: Ideal for isolating direct questions which are critical for FAQ or content that addresses specific user queries.

You can also use this singularly to find results starting with a pattern such as ‘best’ to help filter by search intent.

^best        

4.???? Finding Queries with Specific Keywords: Search for any queries containing a set list of keywords.

^iphone|samsung|nokia        

Example: Useful for targeting content about specific products or topics.

5.???? Detecting Queries Ending with a Certain Word: Isolate queries that conclude with a particular term.

backlink$        

Example: Helps in identifying queries focused on specific products or features, such as software names.

6.???? Query Variation by Singular or Plural Forms: Capture both singular and plural forms in queries.

.*phone.*        

Example: Enhances the comprehensiveness of keyword targeting by including both forms.

7.???? Excluding Specific Keywords with Negative Matching: Want to clean up your data? Use negative matching to filter out queries containing certain brands or irrelevant terms.

You can easily filter out brand searches with negative matching. However, this can also be used to filter out any words from your data that you want.

- Open Google Search Console

- Click “performance”

- Click “new”

- Click “query”

- Select “Custom (regex)” from dropdown

- Select “Doesn’t match regex” from second dropdown

brandl|brandkeyword|brand keywords        

Example: Filters out data that may skew analytics, such as branded searches not related to your targets.

8.???? Queries Requiring Multiple Specific Words: Use this regex pattern to ensure that certain keywords appear together within a query, guaranteeing more targeted results.

(phone.*nokia)        

Example: For precise targeting of content that must include multiple specific terms.

9.???? Mandating Specific Word Order in Queries: Use this regex pattern to find queries where specific words appear in a strict sequence, ensuring precise targeting.

(\bseo\b.*\bsea\b)        

Example: Crucial for targeting niche markets or specific service offerings.

10.? Starting Queries with Specific Characters or Short Words: Target queries initiating with small words or specific characters.

^open\w*        

This would match any queries starting with open, including terms such as ‘opening.’

Page-Specific Regex

Using Regex in Google Search Console is an incredibly powerful way to get a snapshot of how specific categories and topics on your site are doing.

Below are some of the most effective regular expression patterns I use—and you might want to add them to your toolkit too.

1. Finding URLs Containing a Specific Word: Use this regex pattern to identify pages that contain a specific keyword within their URL structure, helping you evaluate content relevance.

.*\/\b(keyword)\b.*        

Example: Useful for pinpointing URLs that directly include terms like 'SEO' or 'Google Ads', helping to evaluate content relevance and SEO performance.

2. Detecting URLs with Specific Keywords Anywhere: Search for URLs that contain one or more specified words anywhere in their structure.

.*\/(keyword1|keyword2|keyword3).*        

Example: Allows for broad monitoring of content related to multiple topics like 'seo', 'marketing', and 'ai'.

3. Analyzing Category Performance by Impressions, Clicks, and Positions: Focus on URLs within specific categories to see their performance metrics.

^https:\/\/example.com\/category\/.*        

Example: Essential for assessing the impact of different content categories on user engagement and search performance.

4. Determining URL Depth by Subdirectory Levels: Use this regex pattern to evaluate how the depth of URL paths relates to your site’s content structuring and accessibility.

^https:\/\/example.com\/([^\/]+\/){1,3}$        

Example: Tracks URLs by their depth, such as distinguishing between top-level pages and deeper, nested content.

5. Finding Pages Beginning with a Specific Word: Use this regex pattern to isolate pages whose URLs start with specific keywords, making it easier to focus on targeted content.

^.*best.*        

Example: Useful for affiliate sites or product pages, like URLs beginning with "best".

6. Locating Pages Ending with a Specific Word: Identify pages whose URLs end with certain terms, often indicating specific types of content or actions.

.*review.*$        

Example: You can find pages that you know end with a specific word. One common example on affiliate websites would be something like “review”

7. Searching Pages Within a Category for Specific Words: Use this regex pattern to retrieve pages within a specified category that contain specific keywords, ensuring you focus on relevant content.

^https://example.com/category/.*ppc.*        

Example: Ideal for analyzing content relevance within categories, such as finding all 'ppc' related articles within a tech category.

8. Find Pages Inside a Category Containing a Specific Words: Equally, you can search for groups of similar words to make things easier.

^https://example.com/category/.*(ppc|other).*        

9. Find URLs Containing Multiple Words In Any Order: This regex is particularly useful for large sites where URL structures are complex and varied.

(.*best)(.*linux)        

Regular expressions (regex) are an invaluable tool for supercharging your SEO efforts. By applying the techniques shared earlier, you can dive deeper into page performance, query types, and other critical aspects of website analytics.

For those interested in expanding their knowledge of regex, the following resources are highly recommended:

RegexOne: A beginner-friendly guide to learning the basics of regex.

Regex For SEO: A specialized resource for applying regex in SEO strategies.

Regex Testing Tool: An online tool to practice and validate your regex patterns in real-time.

Of course, you can use AI to help with regex, but I believe every good SEO should still have basic knowledge and a few favorite expressions up their sleeve.

So if you’re still not convinced, I’m sorry for you—I’m sending you 1 year of luck and positive energy! ?? ??

P.S. Special thanks to Daniel for showing me some really cool stuff with regex years ago, and a shoutout to ChatGPT and Bard for their contributions to this article.

As one of my favorite cartoon networks says: “That’s all, folks!" ?? Until next time! ??

Nikola Minkov

Helping B2B improve their Digital Marketing Strategy 10+ years | Young Scientist | Startup Builder | CEO & Founder at Serpact & SERP Conf. & SERP Acad. | Public Speaker | Rotary Member | Member of Forbes Business Council

3 个月

Nice text, Andrian Alipiev. In the end, the decision to use regex should be based on the complexity of the problem and the long-term benefits it might bring to your workflow.

Petr Vinklárek

SEO padawan & accessibility advocate | former analyst, content manager, and university lecturer

3 个月

Can you show me three people who think regex is not worth it in SEO, please?

Subhash Kannanchery ??

Senior Lead Digital Marketing Specialist at Citrus Informatics (India) Pvt Ltd |Google Certified | Inbound Certified

3 个月

Yes..this is helpful. Thank you

Stephan Czysch

Gründer von searchanalyzer | Selbstst?ndiger SEO-Consultant

3 个月

And to save and load your favourite RegEx, use my Chrome extension GSC Helper ?? https://chromewebstore.google.com/detail/gsc-helper-by-searchanaly/gnhafaadncbkbdkbkjejdaofoameoede

  • 该图片无替代文字
回复

要查看或添加评论,请登录

社区洞察