How to Match or Extract the Nth Word in a Line in Google Sheets

Published on

If you’ve ever wanted to pull out a specific word from a sentence—or check whether the nth word matches something—in Google Sheets, this post is for you.

I’ll walk you through how to extract the nth word from a line using two handy methods, and then show you how to match the nth word using formulas. We’ll use both SPLIT + INDEX and regular expressions (REGEXEXTRACT / REGEXMATCH). Let’s dive in.

Extract the Nth Word from a Sentence in Google Sheets

To keep things simple, let’s use this sentence in cell A2:

Let the cat out of the bag

(I just picked an idiom to make it fun—feel free to try this on your real data.)

Using SPLIT + INDEX to Extract the Nth Word

This is probably the easiest approach when your text is nicely spaced. Here’s the formula:

=INDEX(SPLIT(A2, " "), 0, n)

Just replace n with the word position you want.

To extract the third word (“cat”):

=INDEX(SPLIT(A2, " "), 0, 3)

What’s happening:

  • SPLIT(A2, " ") breaks the sentence into separate words using space
  • INDEX(..., 0, 3) picks the third one

Result:

cat

It’s simple, readable, and works great when your data doesn’t have extra spaces.

Can I use this in an array? Yes, you can:

=INDEX(SPLIT(A2:A, " "), 0, 3)

This formula will extract the 3rd word from each line in a vertical range.

Using REGEXEXTRACT to Extract the Nth Word

Want a formula that uses regex? Here’s how to extract the 3rd word:

=REGEXEXTRACT(A2, "(?:\S+\s+){2}(\S+)")

Let me break it down:

  • (?:\S+\s+){2} skips the first two words (non-capturing group)
  • \S+ captures the 3rd word (non-space characters)

So if you change the {2} to {n-1}, you can pull any word by position. For example:

=REGEXEXTRACT(A2, "(?:\S+\s+){4}(\S+)")

…would get you the fifth word.

Can I use this in an array? Yes, you can:

=ArrayFormula(IFNA(REGEXEXTRACT(A2:A, "(?:\S+\s+){2}(\S+)")))

Both formulas work well—pick based on whether you prefer simplicity or pattern control.

Match the Nth Word in a Line in Google Sheets

Let’s say you now want to check if the 3rd word is “cat”. You’ve got two options: a regex formula (case-sensitive) or a non-regex one using XMATCH (case-insensitive).

Using REGEXMATCH (Case-Sensitive)

Try this:

=REGEXMATCH(A2, "^(?:\S+\s+){2}cat\b")
Google Sheets formula returning TRUE when the 3rd word in a sentence matches the target word using REGEXMATCH

Here’s what it does:

  • ^ anchors the match at the start
  • (?:\S+\s+){2} skips the first two words
  • cat\b matches the exact word “cat”

If the 3rd word is “cat”, it’ll return TRUE. Otherwise, FALSE. Just note: it’s case-sensitive.

Using SPLIT + INDEX + XMATCH to Match the Nth Word

Prefer something without regex? Here’s a cleaner alternative:

=NOT(ISNA(XMATCH("cat", INDEX(SPLIT(A2, " "), 0, 3))))

This one grabs the 3rd word using SPLIT + INDEX, then compares it to “cat” using XMATCH. It’s more forgiving when it comes to letter case.

Wrapping Up

So here’s a quick recap:

To extract the nth word in Google Sheets:

  • Use SPLIT + INDEX if your text is well-structured
  • Use REGEXEXTRACT for more control or compact formulas

To match the nth word:

  • Use REGEXMATCH for case-sensitive matching
  • Use SPLIT + INDEX + XMATCH for a simpler, case-insensitive check

Each method has its place—go with whatever suits your workflow best.

Further Reading

Prashanth KV
Prashanth KV
Your Trusted Google Sheets and Excel Expert Prashanth KV is a Diamond Product Expert in Google Sheets, officially recognized by Google for his contributions to the Docs Editors Help Community and featured in the Google Product Experts Directory. Explore his blog to learn advanced formulas, automation tips, and problem-solving techniques to elevate your spreadsheet skills.

Top Discussions

More like this

Free Monthly Expense Tracker Template in Google Sheets (Dashboard Included)

A monthly expense tracker in Google Sheets helps you record daily expenses, analyze spending...

The Complete Guide to XLOOKUP in Google Sheets (15+ Practical Examples)

The XLOOKUP function largely replaces traditional lookup functions such as LOOKUP, VLOOKUP, and HLOOKUP...

How to Sort and Filter Pivot Tables in Google Sheets (Complete Guide)

Sorting and filtering are two of the most important techniques for analyzing data in...

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.