Connect with us

SEO

A Guide To Regular Expressions (With Use Cases)

Published

on

A Guide To Regular Expressions (With Use Cases)

Perhaps you’ve heard of regex but aren’t quite sure how it can be used in SEO or whether it fits into your own strategy.

Regular expressions, or ‘regex’, are like an in-line programming language for text searches that allow you to include complex search strings, partial matches and wildcards, case-insensitive searches, and other advanced instructions.

You can think of them as searching for a pattern, rather than a specific string of text.

Therefore, they can help you to find entire sets of search results that, at first glance, may appear to have little in common with each other.

Regex expressions are a language all their own and the first time you see one, it can look quite alien.

Advertisement

But they are quite easy to learn and can be used across JavaScript, Python and other programming languages, making them a versatile and powerful SEO tool.

In this guide, you’ll learn common regex operators, how to use more advanced regex filters for SEO, how to use regex in Google Analytics and Google Search Console, and more.

You’ll find examples of regex at work in different ways in SEO, too.

What Does Regex Look Like?

A regular expression typically includes a combination of text that will match exactly in the search results, along with several operators that act more like wildcards to achieve a pattern match rather than an exact text match.

This can include a single-character wildcard, a match for one or more characters, or a match for zero or more characters, as well as optional characters, nested sub-expressions in parentheses, and ‘or’ functions.

By combining these different operations together, you can build a complex expression that can achieve very far-reaching, yet very specific results.

Advertisement

Common Regex Operators

A few examples of common regex operators include:

.         A wildcard match for any single character.

.*       A match for zero or more characters.

.+      A match for one or more characters.

d        A match for any single numerical digit 0-9.

?        Inserted after a character to make it an optional part of the expression.

Advertisement

|        A vertical line or ‘pipe’ character indicates an ‘or’ function.

^       Used to denote the start of a string.

$        Used to denote the end of a string.

( )      Used to nest a sub-expression.

        Inserted before an operator or special character to ‘escape’ it.

Some programming languages, such as JavaScript, allow the inclusion of ‘flags’ after the regex pattern itself, and these can further affect the outcome:

Advertisement

g        Returns all matches instead of just the first one.

i         Returns case-insensitive results.

m       Activates multiline mode.

s        Activates ‘dotall’ mode.

u        Activates full Unicode support.

y        Searches the specific text position (‘sticky’ mode).

Advertisement

As you can see, together these operators and flags start to build up to a complex logical language, giving you the ability to achieve very specific results across large, unordered data sets.

How Do You Use Regex For SEO?

Regex can be used to explore the queries different user segments use, which queries are common to specific content areas, which queries drive traffic to specific parts of your site, and more.

In this article, Hamlet Batista demonstrated how to use regex in Python to analyze server log files, for example.

And in this one, Chris Long showed you how to use regex to extract the position, item, and name of the breadcrumbs associated with each URL of your site as part of a scalable keyword research and segmentation process.

Google encourages SEO pros to share examples of how they’re using regex on Twitter using the hashtag #performanceregex.

Here are a couple tips from SEO Twitter (you’ll notice it’s a pretty quiet hashtag – add your own examples if you have them!):

Advertisement

Using Regex On Google Analytics

One of the most common uses of regex for SEO is in Google Analytics, where regular expressions can be used to set up filters so that you only see the data you want to see.

In this sense, the expression is used to exclude results, rather than to generate a set of inclusive search results.

For example, if you want to exclude data from IP addresses on your local area network, you might filter out 192.168.*.* to remove the full range from 192.168.0.0 to 192.168.255.255.

Advertisement

More Advanced Regex SEO Filters

As a more complex example, let’s imagine you have two brands: regex247 and regex365.

You might want to filter results that match any combination of URLs that contain these brand names, such as regex247.biz or www.regex365.org.

One way to do this is with a fairly simple ‘or’ expression:

.*regex247.*|.*regex365.*

This would remove all matching URLs from your Analytics data, including subfolder paths and specific page URLs that appear on those domain names.

A Word Of Warning

It is worth noting that – similar to your robots.txt file – a poorly written regex expression can quite easily filter out most or all of your data by including an unrestricted wildcard match.

Advertisement

The good news is that in many SEO cases, the filter is only applied to your data at the reporting stage, and by editing or deleting your regex expression, you can restore full visibility to your data.

You can also test regular expressions on a number of online testing tools, in order to see if they achieve the intended outcome – allowing you to ‘sandbox’ your regex expressions before you let them loose across your entire data set.

To create regex filters on Google Analytics, first, navigate to the type of Report you want to create (e.g. Behaviour > Site Content > All Pages or Acquisition > All Traffic > Source/Medium).

Below the graph, at the top of the data table, look for the search box and click advanced to display the advanced filter options.

Here you can include or exclude data based on a particular dimension or metric. In the dropdown list after you select your dimension, choose Matching RegExp and then enter your expression into the text box.

‘Or’ And ‘And’ In Google Analytics Regex

To create an ‘or’ expression in Google Analytics, just include the pipe character (the | vertical stroke symbol) between the appropriate segments of your expression.

Advertisement

Google Analytics regular expressions do not support ‘and’ statements within a single regex; however, you can just add another filter to achieve this.

Below your first regex, just click Add a dimension or metric and enter your next regex. In this way, you can stack as many expressions as you want and they will be processed as a single logical ‘and’ statement when filtering your data.

Using Regex In Google Search Console

In 2021, Google Search Console began supporting the Re2 syntax of regex, allowing webmasters to include and exclude data within the user interface.

You’ll find all metacharacters supported by Google Search Console in this RE2 regex syntax reference on GitHub.

At the time of writing, there is a character limit of 4096 characters (which is usually enough…).

Examples you can use in Search Console can be filtering for queries containing a specific brand and the variations users could type, such as Facebook:

Advertisement

.*facebook.*|face*book.*|fb.*|fbook.*|f*book.*

Filter out users finding your website through “commercial” intent terms:

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

Related: Google Search Console Adds New Regex Filter Options

Why Is Regex Important For SEO?

Finally, why does all this matter?

Well, it’s all about taking control of your data and filtering out the parts of it that don’t help you to improve your SEO – whether that’s particular pages or parts of your website, traffic from a specific source or medium, or your own local network data.

Advertisement

You can create quite simple regex expressions to achieve a basic ‘include’ or ‘exclude’ filter, or write longer expressions that work similarly to programming code to achieve complex and very specific results.

And with the right regex for each campaign, you can verify that your SEO efforts are achieving your aims, ambitions, and outcomes – a powerful way to prove positive ROI on your future SEO investments.

More resources:


Featured Image: Optura Design/Shutterstock




Source link

Keep an eye on what we are doing
Be the first to get latest updates and exclusive content straight to your email inbox.
We promise not to spam you. You can unsubscribe at any time.
Invalid email address

SEO

Google On Hyphens In Domain Names

Published

on

By

What Google says about using hyphens in domain names

Google’s John Mueller answered a question on Reddit about why people don’t use hyphens with domains and if there was something to be concerned about that they were missing.

Domain Names With Hyphens For SEO

I’ve been working online for 25 years and I remember when using hyphens in domains was something that affiliates did for SEO when Google was still influenced by keywords in the domain, URL, and basically keywords anywhere on the webpage. It wasn’t something that everyone did, it was mainly something that was popular with some affiliate marketers.

Another reason for choosing domain names with keywords in them was that site visitors tended to convert at a higher rate because the keywords essentially prequalified the site visitor. I know from experience how useful two-keyword domains (and one word domain names) are for conversions, as long as they didn’t have hyphens in them.

A consideration that caused hyphenated domain names to fall out of favor is that they have an untrustworthy appearance and that can work against conversion rates because trustworthiness is an important factor for conversions.

Lastly, hyphenated domain names look tacky. Why go with tacky when a brandable domain is easier for building trust and conversions?

Advertisement

Domain Name Question Asked On Reddit

This is the question asked on Reddit:

“Why don’t people use a lot of domains with hyphens? Is there something concerning about it? I understand when you tell it out loud people make miss hyphen in search.”

And this is Mueller’s response:

“It used to be that domain names with a lot of hyphens were considered (by users? or by SEOs assuming users would? it’s been a while) to be less serious – since they could imply that you weren’t able to get the domain name with fewer hyphens. Nowadays there are a lot of top-level-domains so it’s less of a thing.

My main recommendation is to pick something for the long run (assuming that’s what you’re aiming for), and not to be overly keyword focused (because life is too short to box yourself into a corner – make good things, course-correct over time, don’t let a domain-name limit what you do online). The web is full of awkward, keyword-focused short-lived low-effort takes made for SEO — make something truly awesome that people will ask for by name. If that takes a hyphen in the name – go for it.”

Pick A Domain Name That Can Grow

Mueller is right about picking a domain name that won’t lock your site into one topic. When a site grows in popularity the natural growth path is to expand the range of topics the site coves. But that’s hard to do when the domain is locked into one rigid keyword phrase. That’s one of the downsides of picking a “Best + keyword + reviews” domain, too. Those domains can’t grow bigger and look tacky, too.

That’s why I’ve always recommended brandable domains that are memorable and encourage trust in some way.

Advertisement

Read the post on Reddit:

Are domains with hyphens bad?

Read Mueller’s response here.

Featured Image by Shutterstock/Benny Marty

Source link

Keep an eye on what we are doing
Be the first to get latest updates and exclusive content straight to your email inbox.
We promise not to spam you. You can unsubscribe at any time.
Invalid email address
Continue Reading

SEO

Reddit Post Ranks On Google In 5 Minutes

Published

on

By

Google apparently ranks Reddit posts within minutes

Google’s Danny Sullivan disputed the assertions made in a Reddit discussion that Google is showing a preference for Reddit in the search results. But a Redditor’s example proves that it’s possible for a Reddit post to rank in the top ten of the search results within minutes and to actually improve rankings to position #2 a week later.

Discussion About Google Showing Preference To Reddit

A Redditor (gronetwork) complained that Google is sending so many visitors to Reddit that the server is struggling with the load and shared an example that proved that it can only take minutes for a Reddit post to rank in the top ten.

That post was part of a 79 post Reddit thread where many in the r/SEO subreddit were complaining about Google allegedly giving too much preference to Reddit over legit sites.

The person who did the test (gronetwork) wrote:

“…The website is already cracking (server down, double posts, comments not showing) because there are too many visitors.

…It only takes few minutes (you can test it) for a post on Reddit to appear in the top ten results of Google with keywords related to the post’s title… (while I have to wait months for an article on my site to be referenced). Do the math, the whole world is going to spam here. The loop is completed.”

Advertisement

Reddit Post Ranked Within Minutes

Another Redditor asked if they had tested if it takes “a few minutes” to rank in the top ten and gronetwork answered that they had tested it with a post titled, Google SGE Review.

gronetwork posted:

“Yes, I have created for example a post named “Google SGE Review” previously. After less than 5 minutes it was ranked 8th for Google SGE Review (no quotes). Just after Washingtonpost.com, 6 authoritative SEO websites and Google.com’s overview page for SGE (Search Generative Experience). It is ranked third for SGE Review.”

It’s true, not only does that specific post (Google SGE Review) rank in the top 10, the post started out in position 8 and it actually improved ranking, currently listed beneath the number one result for the search query “SGE Review”.

Screenshot Of Reddit Post That Ranked Within Minutes

Anecdotes Versus Anecdotes

Okay, the above is just one anecdote. But it’s a heck of an anecdote because it proves that it’s possible for a Reddit post to rank within minutes and get stuck in the top of the search results over other possibly more authoritative websites.

hankschrader79 shared that Reddit posts outrank Toyota Tacoma forums for a phrase related to mods for that truck.

Advertisement

Google’s Danny Sullivan responded to that post and the entire discussion to dispute that Reddit is not always prioritized over other forums.

Danny wrote:

“Reddit is not always prioritized over other forums. [super vhs to mac adapter] I did this week, it goes Apple Support Community, MacRumors Forum and further down, there’s Reddit. I also did [kumo cloud not working setup 5ghz] recently (it’s a nightmare) and it was the Netgear community, the SmartThings Community, GreenBuildingAdvisor before Reddit. Related to that was [disable 5g airport] which has Apple Support Community above Reddit. [how to open an 8 track tape] — really, it was the YouTube videos that helped me most, but it’s the Tapeheads community that comes before Reddit.

In your example for [toyota tacoma], I don’t even get Reddit in the top results. I get Toyota, Car & Driver, Wikipedia, Toyota again, three YouTube videos from different creators (not Toyota), Edmunds, a Top Stories unit. No Reddit, which doesn’t really support the notion of always wanting to drive traffic just to Reddit.

If I guess at the more specific query you might have done, maybe [overland mods for toyota tacoma], I get a YouTube video first, then Reddit, then Tacoma World at third — not near the bottom. So yes, Reddit is higher for that query — but it’s not first. It’s also not always first. And sometimes, it’s not even showing at all.”

hankschrader79 conceded that they were generalizing when they wrote that Google always prioritized Reddit. But they also insisted that that didn’t diminish what they said is a fact that Google’s “prioritization” forum content has benefitted Reddit more than actual forums.

Why Is The Reddit Post Ranked So High?

It’s possible that Google “tested” that Reddit post in position 8 within minutes and that user interaction signals indicated to Google’s algorithms that users prefer to see that Reddit post. If that’s the case then it’s not a matter of Google showing preference to Reddit post but rather it’s users that are showing the preference and the algorithm is responding to those preferences.

Advertisement

Nevertheless, an argument can be made that user preferences for Reddit can be a manifestation of Familiarity Bias. Familiarity Bias is when people show a preference for things that are familiar to them. If a person is familiar with a brand because of all the advertising they were exposed to then they may show a bias for the brand products over unfamiliar brands.

Users who are familiar with Reddit may choose Reddit because they don’t know the other sites in the search results or because they have a bias that Google ranks spammy and optimized websites and feel safer reading Reddit.

Google may be picking up on those user interaction signals that indicate a preference and satisfaction with the Reddit results but those results may simply be biases and not an indication that Reddit is trustworthy and authoritative.

Is Reddit Benefiting From A Self-Reinforcing Feedback Loop?

It may very well be that Google’s decision to prioritize user generated content may have started a self-reinforcing pattern that draws users in to Reddit through the search results and because the answers seem plausible those users start to prefer Reddit results. When they’re exposed to more Reddit posts their familiarity bias kicks in and they start to show a preference for Reddit. So what could be happening is that the users and Google’s algorithm are creating a self-reinforcing feedback loop.

Is it possible that Google’s decision to show more user generated content has kicked off a cycle where more users are exposed to Reddit which then feeds back into Google’s algorithm which in turn increases Reddit visibility, regardless of lack of expertise and authoritativeness?

Featured Image by Shutterstock/Kues

Advertisement

Source link

Keep an eye on what we are doing
Be the first to get latest updates and exclusive content straight to your email inbox.
We promise not to spam you. You can unsubscribe at any time.
Invalid email address
Continue Reading

SEO

WordPress Releases A Performance Plugin For “Near-Instant Load Times”

Published

on

By

WordPress speculative loading plugin

WordPress released an official plugin that adds support for a cutting edge technology called speculative loading that can help boost site performance and improve the user experience for site visitors.

Speculative Loading

Rendering means constructing the entire webpage so that it instantly displays (rendering). When your browser downloads the HTML, images, and other resources and puts it together into a webpage, that’s rendering. Prerendering is putting that webpage together (rendering it) in the background.

What this plugin does is to enable the browser to prerender the entire webpage that a user might navigate to next. The plugin does that by anticipating which webpage the user might navigate to based on where they are hovering.

Chrome lists a preference for only prerendering when there is an at least 80% probability of a user navigating to another webpage. The official Chrome support page for prerendering explains:

“Pages should only be prerendered when there is a high probability the page will be loaded by the user. This is why the Chrome address bar prerendering options only happen when there is such a high probability (greater than 80% of the time).

There is also a caveat in that same developer page that prerendering may not happen based on user settings, memory usage and other scenarios (more details below about how analytics handles prerendering).

Advertisement

The Speculative Loading API solves a problem that previous solutions could not because in the past they were simply prefetching resources like JavaScript and CSS but not actually prerendering the entire webpage.

The official WordPress announcement explains it like this:

Introducing the Speculation Rules API
The Speculation Rules API is a new web API that solves the above problems. It allows defining rules to dynamically prefetch and/or prerender URLs of certain structure based on user interaction, in JSON syntax—or in other words, speculatively preload those URLs before the navigation. This API can be used, for example, to prerender any links on a page whenever the user hovers over them.”

The official WordPress page about this new functionality describes it:

“The Speculation Rules API is a new web API… It allows defining rules to dynamically prefetch and/or prerender URLs of certain structure based on user interaction, in JSON syntax—or in other words, speculatively preload those URLs before the navigation.

This API can be used, for example, to prerender any links on a page whenever the user hovers over them. Also, with the Speculation Rules API, “prerender” actually means to prerender the entire page, including running JavaScript. This can lead to near-instant load times once the user clicks on the link as the page would have most likely already been loaded in its entirety. However that is only one of the possible configurations.”

The new WordPress plugin adds support for the Speculation Rules API. The Mozilla developer pages, a great resource for HTML technical understanding describes it like this:

“The Speculation Rules API is designed to improve performance for future navigations. It targets document URLs rather than specific resource files, and so makes sense for multi-page applications (MPAs) rather than single-page applications (SPAs).

The Speculation Rules API provides an alternative to the widely-available <link rel=”prefetch”> feature and is designed to supersede the Chrome-only deprecated <link rel=”prerender”> feature. It provides many improvements over these technologies, along with a more expressive, configurable syntax for specifying which documents should be prefetched or prerendered.”

Advertisement

See also: Are Websites Getting Faster? New Data Reveals Mixed Results

Performance Lab Plugin

The new plugin was developed by the official WordPress performance team which occasionally rolls out new plugins for users to test ahead of possible inclusion into the actual WordPress core. So it’s a good opportunity to be first to try out new performance technologies.

The new WordPress plugin is by default set to prerender “WordPress frontend URLs” which are pages, posts, and archive pages. How it works can be fine-tuned under the settings:

Settings > Reading > Speculative Loading

Browser Compatibility

The Speculative API is supported by Chrome 108 however the specific rules used by the new plugin require Chrome 121 or higher. Chrome 121 was released in early 2024.

Browsers that do not support will simply ignore the plugin and will have no effect on the user experience.

Check out the new Speculative Loading WordPress plugin developed by the official core WordPress performance team.

Advertisement

How Analytics Handles Prerendering

A WordPress developer commented with a question asking how Analytics would handle prerendering and someone else answered that it’s up to the Analytics provider to detect a prerender and not count it as a page load or site visit.

Fortunately both Google Analytics and Google Publisher Tags (GPT) both are able to handle prerenders. The Chrome developers support page has a note about how analytics handles prerendering:

“Google Analytics handles prerender by delaying until activation by default as of September 2023, and Google Publisher Tag (GPT) made a similar change to delay triggering advertisements until activation as of November 2023.”

Possible Conflict With Ad Blocker Extensions

There are a couple things to be aware of about this plugin, aside from the fact that it’s an experimental feature that requires Chrome 121 or higher.

A comment by a WordPress plugin developer that this feature may not work with browsers that are using the uBlock Origin ad blocking browser extension.

Download the plugin:
Speculative Loading Plugin by the WordPress Performance Team

Read the announcement at WordPress
Speculative Loading in WordPress

Advertisement

See also: WordPress, Wix & Squarespace Show Best CWV Rate Of Improvement

Source link

Keep an eye on what we are doing
Be the first to get latest updates and exclusive content straight to your email inbox.
We promise not to spam you. You can unsubscribe at any time.
Invalid email address
Continue Reading

Trending

Follow by Email
RSS