Excel REGEXEXTRACT function

Pulls out the part of a text that matches a pattern, such as an order number. In Spanish Excel it is called REGEXEXTRACCION.

Syntax

English Excel

=REGEXEXTRACT(text, pattern, [return_mode], [case_sensitivity])

Spanish Excel (Mexico)

=REGEXEXTRACCION(texto, patrón, [modo_de_retorno], [distinción_de_mayúsculas])

Spanish Excel (Spain, Latin America)

=REGEXEXTRACCION(texto; patrón; [modo_de_retorno]; [distinción_de_mayúsculas])

ArgumentWhat it is
textThe text to extract from.
patternThe regular expression.
return_modeoptional0 the first match, 1 all of them, 2 the groups in parentheses.
case_sensitivityoptional0 is case-sensitive, 1 is not.

Example

A regular expression describes a text pattern: \d is a digit, \D anything that is not, [A-Z] a capital letter, {4} repeats 4 times, + one or more, ^ and $ mark start and end. REGEXTEST says whether the text fits the pattern, REGEXEXTRACT pulls out the matching part and REGEXREPLACE replaces it.

=REGEXEXTRACT(C2,"\d+")

Common mistake

Excel 365 only. The result is text: wrap it in VALUE if you need to add it up. With no match it returns #N/A.

About Ads

This site uses Google AdSense to display ads. These ads help us keep WebHerramientas completely free. Ads are managed by Google and meet strict security and privacy standards.

Advertising
Loading ad...

Ads help us keep WebHerramientas free for everyone

Practice REGEXEXTRACT

Type the formula in the sheet and check it instantly. Spanish or English function names both work. See all lessons

Regular expressions: REGEXTEST, REGEXEXTRACT and REGEXREPLACE

A regular expression describes a text pattern: \d is a digit, \D anything that is not, [A-Z] a capital letter, {4} repeats 4 times, + one or more, ^ and $ mark start and end. REGEXTEST says whether the text fits the pattern, REGEXEXTRACT pulls out the matching part and REGEXREPLACE replaces it.

Step 1/3

In B2, check whether each code has exactly 3 capital letters, a hyphen and 4 digits.

B2
ABCDEFG
1CodeValid?MessageNumberPhoneDigits only
2MEX-2041Order 4521 shipped55-1234-5678
3mx-2018Invoice 778 pending(33) 9876 5432
4GDL-9932Ticket 30215 open81 2233 4455
5QRO-12345Customer 66 called+52 222 111 0099
6MTY-7781Shipment 1290 delayed442.555.7788
7

Tip: while typing, click a cell or drag across several to insert their reference. F4 anchors the reference with $.

Frequently asked questions

What is REGEXEXTRACT called in Spanish?
In Spanish Excel it is REGEXEXTRACCION. The formula =REGEXEXTRACT(C2,"\d+") is written =REGEXEXTRACCION(C2;"\d+") (or with commas in Mexico).
Why does REGEXEXTRACT use semicolons in some Excel versions?
It depends on regional settings. Where the comma is the decimal mark (Spain, much of South America), Excel separates arguments with semicolons. English Excel and Mexican Spanish Excel use commas.
What is the most common REGEXEXTRACT mistake?
Excel 365 only. The result is text: wrap it in VALUE if you need to add it up. With no match it returns #N/A.