A regex email parser for Google Sheets comes down to one function, REGEXEXTRACT, plus a habit of wrapping every pattern so a missing field leaves a blank instead of an error. Google Sheets has no TEXTBEFORE or TEXTAFTER, so the “text before” and “text after” jobs those Excel functions do are handled with REGEXEXTRACT or SPLIT. This guide shows the patterns for order numbers, amounts and dates, how each one fails, and how the same logic carries over to the custom filters in xtractor.

Does Google Sheets have TEXTBEFORE and TEXTAFTER?
No, Google Sheets does not have TEXTBEFORE or TEXTAFTER; they are Excel functions. Google’s own list of text functions includes REGEXEXTRACT, REGEXMATCH, REGEXREPLACE and SPLIT but neither of the two, and a formula that uses them returns #NAME?. Microsoft documents TEXTBEFORE as TEXTBEFORE(text, delimiter, [instance_num], [match_mode], [match_end], [if_not_found]), available in Microsoft 365, Excel for the web and Excel 2024.
If you found a TEXTBEFORE example for Sheets, it was written for Excel or relies on an equivalent. Here are the Sheets versions of the common jobs, using a line from an order email in A2:
| Job | Excel | Google Sheets |
|---|---|---|
| Text after a marker | =TEXTAFTER(A2,"Order #") |
=REGEXEXTRACT(A2,"Order #(.*)") |
| Text before a marker | =TEXTBEFORE(A2," placed") |
=INDEX(SPLIT(A2," placed",FALSE),1,1) |
| Text between two markers | =TEXTBEFORE(TEXTAFTER(A2,"Order #")," placed") |
=REGEXEXTRACT(A2,"Order #(.*?) placed") |
| Value when the marker is missing | the if_not_found argument |
wrap the formula in IFNA(...,"") |
The third argument of SPLIT matters. Left at its default, SPLIT treats a multi-character delimiter as a set of separate characters and cuts the text at every one of them. Passing FALSE makes it split on the whole phrase.
How do you extract an order number from an email with REGEXEXTRACT?
Use REGEXEXTRACT with the text that sits in front of the number outside the capture group and the number itself inside it. Google’s documentation says the function returns the first match, that each capture group goes into its own column, and that Sheets uses RE2 syntax. With one group, you get only what the group matched.
Take this line from an order confirmation, pasted into A2:
Thanks for your order! Order #SH-48213 placed on 2026-11-14. Order total: $1,284.50 USD. Ship to: Dana Reyes, Austin TX.
Put these headers in row 1: Email text, Order number, Amount, Date. Then enter the formula in B2:
=REGEXEXTRACT(A2, "Order #([A-Z]+-\d+)")
It returns SH-48213. The pattern reads as: the literal text “Order #”, then one or more capital letters, a hyphen and one or more digits. If your order numbers are plain digits, use Order #(\d+). If the prefix varies in length, keep [A-Z]+ rather than counting letters.
How do you pull amounts and dates out of the same email?
Capture the digits only, then convert the text to a number or a date, because REGEXEXTRACT always returns text. In C2:
=VALUE(SUBSTITUTE(REGEXEXTRACT(A2, "Order total: \$([\d,]+\.\d{2})"), ",", ""))
The backslash before the dollar sign is needed because $ means “end of text” in a pattern. REGEXEXTRACT returns 1,284.50 as text, SUBSTITUTE removes the thousands comma and VALUE turns the result into 1284.5. Format the column as currency afterwards. If your spreadsheet locale uses a decimal comma, the pattern and the SUBSTITUTE step both need swapping, and the locale guide for Sheets formulas covers the separator side of that.
For the date in D2, an ISO date is the easiest to convert:
=DATEVALUE(REGEXEXTRACT(A2, "placed on (\d{4}-\d{2}-\d{2})"))
Format D2 as a date. Emails that write “14 Nov 2026” or “11/14/2026” need a pattern for that layout, and whether DATEVALUE reads the result depends on the sheet’s locale, so test one row before filling down.
What goes wrong with regex in Sheets, and how do you handle it?
Most failures come from five behaviours, and each has a one-line fix.
- A missing field returns #N/A. Wrap the formula:
=IFNA(REGEXEXTRACT(A2, "Order #([A-Z]+-\d+)"), ""). A blank cell is easier to audit than an error that spreads through a total. - Matching is case-sensitive. Start the pattern with
(?i)to ignore case:(?i)order total: \$([\d,]+\.\d{2}). - Only the first match is returned. If an email lists several line items, REGEXEXTRACT gives you the first. Anchor the pattern to the label you want, such as “Order total:”, instead of matching any dollar amount.
- A dot does not match a line break. For a body that spans lines, add
(?s)at the start or use\swhere the break falls. - RE2 has no lookahead or lookbehind. Put the leading text outside the group, as in the examples above, rather than reaching for
(?<=Order #).
Check any pattern against at least five real emails before trusting it, including one where the field is absent and one with an unusual value, such as a refund with a negative total.
What if the layout changes between emails?
Chain one pattern per layout, newest first, and let the first match win. If your store sends “Order #SH-48213” in one template and “Order number: 90117” in another:
=IFNA(REGEXEXTRACT(A2, "Order #([A-Z]+-\d+)"), IFNA(REGEXEXTRACT(A2, "Order number: (\d+)"), ""))
This works for two or three layouts and gets hard to read after that. It is the point at which a tool that keeps each layout as its own rule pays off, as covered in multi-context parsing for varying email layouts and in custom parsing rules for inconsistent formats.
Where do these patterns fit when you parse Gmail at scale?
Formulas work on text already sitting in cells, and the same text-before, text-after and regex logic is what xtractor’s custom filters apply to emails as they are imported from Gmail. xtractor is a Google Workspace add-on that runs inside Google Sheets. You search Gmail by subject, sender, date or content, define the fields to extract, and the values land as rows and columns in your own sheet. Filters can be text-before/text-after rules or regex filters, a search and its filters can be saved, and multiple parsing contexts let one search handle emails whose format varies.
A practical way to use this guide: prove each pattern with a formula on a few pasted emails, then build the matching filter on a saved search and run it over the full mailbox. Test the filter against a handful of real emails first, the same way you would the formula, since a pattern that works in a Sheets cell is a starting point rather than a guarantee.
Some limits to plan around:
- xtractor reads Gmail only, so Outlook and other mailboxes are out.
- It does not parse attachments such as PDF invoices, only what is in the email itself.
- Imports can be bulk (thousands of emails at once) or scheduled, daily on Starter and Pro, every 4 hours on Premium and hourly on Business.
- Plans cap fields per search: 1 on the free plan, 2 on Starter, 5 on Pro. Order number, amount and date are three fields, so the Pro plan ($45 a month billed monthly, $10 a month billed annually) is the first that fits them in a single search if each counts as a field. New accounts get 100 trial emails, and the free plan allows 10 emails a day and 50 a month.
For a worked version of the same task without formulas, see extracting order numbers and amounts from emails into Sheets. The broader picture of getting email data into a sheet is in the email to Google Sheets guide.
FAQ
Can I use TEXTBEFORE in Google Sheets?
No. It returns #NAME?. Use REGEXEXTRACT or SPLIT with FALSE as the third argument.
How do I extract text between two words in Google Sheets?
Use a lazy match: =REGEXEXTRACT(A2,"Order #(.*?) placed") returns whatever sits between the two markers.
Why does REGEXEXTRACT return a number as text?
It only returns text. Wrap it in VALUE, and remove thousands separators with SUBSTITUTE first.
What regex flavour does Google Sheets use?
RE2, which has no lookahead or lookbehind.
Does the same regex work in xtractor?
Test it. xtractor supports regex filters and text-before/text-after rules, but verify each pattern on real emails from your mailbox before running a full import.
Start with the three formulas above on one pasted email, then set up the same three fields as filters on your own Gmail and compare the rows they give you.