Find Long-Tail Queries in Search Console with Regex
About 24 minutes
In the last two lessons, we more or less knew the text we were looking for. Once we searched for price, once for several options, (price|cost|how much), and once we set where the text was, ^how or iphone$.
But today the problem is different. I want every query made of 5 words or more, or 7 words or more, or just 5 to 7 words. Here I don't know the words themselves: they could be anything. But there's one thing they share: the number of words. And this is where, for the first time, we use regex to describe the shape of the query itself instead of searching for known text.
Before we write regex, what are we actually counting?
When I say "a 5-word query", I need the regex to understand two things: what's a word? And what's the space that separates two words?
The first new idea: \S
We have \S, which means: any character that isn't a space. A letter, a digit, or any other character, as long as it isn't whitespace. But on its own it stands for one character only, and we don't want one character; we want a whole word.
The + symbol means repeat once or more
With \S+ we're saying: give me a character that isn't a space, and repeat it once or more. Google itself uses \S to mean any character that isn't a space, and + to mean repeat the previous item once or more, in Search Console regex.
\S+ = "a word". But regex doesn't understand what a word is in the language sense; it sees "a run of characters with no space between them". So "iphone-17" or "price?" each count as one piece. So when we say "the number of words", we're really counting the pieces of text separated by spaces.Let's try: ^\S+$: the start of the text, one piece with no spaces, the end of the text. So, roughly, a one-word query.
^\S+$- iphone
- laptop
- iphone 17
- iphone price
- seo
- learn seo
Great, one word. Now we want two
The \s symbol means a space, or whitespace. If we write \S+\s+\S+, read it as: a word + one or more spaces + a word. We used \s+, not just \s, so the pattern copes if there's more than one space between two pieces. The RE2 engine Search Console uses supports \s and \S, as well as + for repeating once or more.
A query of exactly two words: ^\S+\s+\S+$
^\S+\s+\S+$- iphone
- iphone 17
- iphone price
- iphone price uk
- learn seo
- best laptop for work
What if we want 3 words?
We could repeat \s+\S+ as many times as we need, but picture wanting 10 words: do we keep repeating it 10 times? It works, but it doesn't make sense. Regex has a better way: {2} after a piece means "repeat the previous piece exactly twice".
So for a 3-word query: the first word is already there, \S+, and then "a space + a word" repeats twice: ^\S+(\s+\S+){2}$. The RE2 engine supports {n} for repeating a set number of times.
^\S+(\s+\S+){2}$- learn seo
- learn seo online
- learn seo online for free
- how to learn seo properly
{5} directly. The first word is already there, \S+, so only the extra words repeat. 5 words = the first word + 4 extra words, so ^\S+(\s+\S+){4}$, not {5}.Now we're back to the problem we started from: 5 words or more
We don't want exactly 5 words; we want 5 words or more. Here we use {4,}, which means: repeat the previous piece at least 4 times, and possibly more. RE2 supports the {n,} form, meaning repeat n times or more.
- 1^ — start at the beginning of the query
- 2
\S+ — the first word - 3
(\s+\S+) — a space, then another word - 4
{4,} — repeat "space + word" 4 times or more - 5$ — and stop at the end of the query
- 6So: a whole query with 5 words or more
^\S+(\s+\S+){4,}$- iphone 17
- iphone 17 price uk
- how much is the iphone 17
- best place to buy iphone 17
- what is the best iphone for photography
Don't memorize 5, 7 and 10 as ready-made patterns. Understand the rule: the number of words you want, minus 1. If you want 7+: 7 - 1 = 6, so we write {6,}. If you want 10+: 10 - 1 = 9, so we write {9,}.
This pattern means 7 words or more (7 - 1 = 6). How many of these six queries will match?
^\S+(\s+\S+){6,}$- iphone
- iphone 17
- iphone 17 price uk
- how much is the iphone 17
- what is the best iphone 17 for photography
- best phone for photography in low light 2026
What about only 5 to 7 words?
We have the {n,m} form, which means: repeat from n to m times. If you want 5 to 7 words, the first word is already there, so the extra words go from 4 to 6: ^\S+(\s+\S+){4,6}$. RE2 supports {n,m} for repeating between a minimum and a maximum.
^\S+(\s+\S+){4,6}$- iphone 17 pro
- iphone 17 price in uk
- how much is iphone 17 uk
- what is the price of iphone 17
- what is the best iphone 17 for photography right now
The long tail and how people search now
With AI-powered search, users can ask longer, more specific questions. And in AI Mode in particular, Google treats a follow-up question as a new query. That makes a long-tail segment very useful for exploring. For example, if you find a repeating pattern of long queries with high impressions and very few clicks, or none, that could be a sign that part of the site's visibility is happening in search experiences where the user can get an answer without clicking.
Now let's use the same idea for something different: numbers
The \d symbol means one digit from 0 to 9. Google documents \d as a single digit from 0 to 9 in Search Console regex.
\d- iphone
- iphone 17
- iphone 16 price
- iphone pro
- best iphone 2026
What if you want a whole number? \d+ means one or more digits in a row. And if you want a number with a set number of digits, \d{4} means 4 digits in a row. But careful: regex doesn't know "2026" is a year; it just sees "four digits in a row". If you specifically want certain years, it's better to be precise with what we learned in lesson 1:
(2025|2026|2027)- best laptop 2026
- articles 2024
- plan 2027
Notice we're not learning new regex every time; we're combining the tools we know in different ways.
An important mistake: forgetting ^ and $
If you want one-word queries, is \S+ enough? No. Because Search Console uses a partial match, and in "iphone price in uk" there are lots of pieces that match \S+. You want to say: the whole query has to be one word. That's why we need ^\S+$. Same problem with 5 words: without ^ and $, we're no longer describing the length of the whole query as precisely.
A point about English text
\S+ works well with English because it doesn't rely on \w. \w only covers letters, digits and the underscore, so it would split "wi-fi" or "iphone's" into two pieces at the hyphen or the apostrophe. \S+ says "any run of characters that aren't spaces", so "wi-fi" stays one word. We'll look at \w and word boundaries in detail in the lesson on messy queries.
^\S+\s+\S+$- wi-fi router
iphone's camera- best wi-fi router
A summary of the new tools
- 1
One word: ^\S+$ - 2
Exactly two words: ^\S+\s+\S+$ - 3
Exactly 3 words: ^\S+(\s+\S+){2}$ - 4
5 words or more: ^\S+(\s+\S+){4,}$ - 5
7 words or more: ^\S+(\s+\S+){6,}$ - 6
10 words or more: ^\S+(\s+\S+){9,}$ - 7
5 to 7 words: ^\S+(\s+\S+){4,6}$
The list isn't what matters. What matters is that you can build any of them yourself.
You have: seo, learn seo, learn seo for beginners, how to learn seo from scratch, how to learn seo for websites from scratch for free. You want: the queries with 5 words or more. Think first: 5 words, minus 1, makes 4.
- seo
- learn seo
- learn seo for beginners
- how to learn seo from scratch
- how to learn seo for websites from scratch for free
You want: the queries with 7 words or more. Instead of memorizing the solution, work it out: 7 - 1 = ?
- learn seo
- how to learn seo from scratch
- how to learn seo for websites properly from scratch
You want: the queries with 10 words or more. Work it out: 10 - 1 = 9.
- learn seo
- what is the best laptop for an seo who uses screaming frog and python
You want: the queries with 4 to 6 words. The first word counts already, so the extra words go from 3 to 5.
- iphone 17
- iphone 17 price uk
- how much is the new iphone 17 really
- what is the best iphone 17 for photography right now in the uk
You have: iphone, iphone 17, iphone pro, best iphone 2026, macbook, macbook m5, best laptop 2026. You want: the queries with at least one digit.
- iphone
- iphone 17
- iphone pro
- best iphone 2026
- macbook
- macbook m5
- best laptop 2026
Stop here: will macbook m5 show up? Yes, because the 5 in it is a digit. A good example of regex carrying out the rule literally.
The practical test
You have: iphone, iphone 17, iphone 17 price, iphone 17 price uk, iphone 17 price in uk, how much is the iphone 17, what is the price of iphone 17 pro, what is the best iphone 17 for photography, best phone for night photography at a good price 2026.
Queries with 5 words or more
Write a regex that shows the queries made of 5 words or more.
- · iphone 17 price in uk
- · how much is the iphone 17
- · what is the price of iphone 17 pro
- · what is the best iphone 17 for photography
- · best phone for night photography at a good price 2026
- · iphone
- · iphone 17
- · iphone 17 price
- · iphone 17 price uk
Once you've built the long-query segment, write one real SEO question you could answer with it. Not "I managed to pull out the long queries", but something like: did the updated pages start picking up impressions from more specific queries than in the previous period?
A real test of understanding
If I told you "I want queries of 12 words or more", you shouldn't look for a 12-word pattern. You should think: 12 words → the first word is already there → 12 - 1 = 11 → so ^\S+(\s+\S+){11,}$. If you can build it yourself, you've understood the lesson.
Before the next lesson
We started the course searching for words we knew, then we started controlling where they are, and today we made a different leap: we can now ask about something without knowing the words at all. The number of words, whether there are digits, the shape of the query. In the next lesson we'll start using these tools together to build real SEO segments: brand, non-brand, questions, comparisons, price and buying queries, and the different ways the same brand is typed. And then we won't stop at writing a pattern; we'll start seeing how a weak pattern can give you a misleading segment.
Well done, you reached the end of the lesson.