# How to extract text between two words in Google Sheets

Capture what sits between the words with a lazy group: =REGEXEXTRACT(A2,"for (.+?) shipped"). Build the pattern from cells to change the words easily.

**Google Sheets:** `=IFERROR(REGEXEXTRACT(A2,$E$1&" (.+?) "&$G$1),"")`

**Excel:** In Excel 365, no pattern is needed: =IFERROR(TEXTBEFORE(TEXTAFTER(A2,$E$1&" ")," "&$G$1),"") returns the same text.

## Example

Sample data (row 1 is the header):

| A | B | C | D | E | F | G |
| --- | --- | --- | --- | --- | --- | --- |
| Log entry | Customer |  | After | for | Before | shipped |
| Order 4471 for Contoso shipped today |  |  |  |  |  |  |
| Order 4472 for Northwind Traders shipped late |  |  |  |  |  |  |
| Order 4473 for Fabrikam shipped |  |  |  |  |  |  |
| Order 4474 for Adatum Corp shipped today |  |  |  |  |  |  |
| Order 4475 cancelled |  |  |  |  |  |  |

Formula in B2, filled to B6: `=IFERROR(REGEXEXTRACT(A2,$E$1&" (.+?) "&$G$1),"")`

Result: Contoso; Northwind Traders; Fabrikam; Adatum Corp; 

## How it works

The pattern becomes `for (.+?) shipped`. The brackets capture what REGEXEXTRACT returns, and `.+?` means "as few characters as possible", so the match stops at the first "shipped" after "for". IFERROR returns a blank for "Order 4475 cancelled", which has neither word.

## Other ways

- `=IFERROR(REGEXEXTRACT(A2,"(?i)"&$E$1&" (.+?) "&$G$1),"")`: Ignores case, so "FOR" and "Shipped" match too.

## Common mistakes

- A greedy `(.+)` runs to the last "shipped" in the text instead of the first.
- Words that contain pattern characters, like "Inc." or "(US)", must be escaped with a backslash.

## Questions

**How do I extract everything after a word?**

Capture to the end: `=REGEXEXTRACT(A2,"for (.+)$")`.

**How do I trim spaces from the result?**

Wrap it in TRIM: `=TRIM(REGEXEXTRACT(A2,"for(.+?)shipped"))`.

Every formula and result on this page was checked by running it in the Spreadsheet Practice formula engine on 2026-10-30.

Source: https://spreadsheetpractice.com/formulas/extract-text-between-two-words-in-google-sheets
