Excel functions / Text

REGEXEXTRACT function

The part of the text that matches a regular expression: the first match, all of them, or its groups.

Syntax

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

Arguments

When to use it

REGEXEXTRACT finds the part of a text that matches a pattern, called a regular expression. The pattern describes the shape of what you want: [0-9]+ is a run of digits, [A-Z]{2} is two capital letters.

It does in one step what used to take MID, FIND and LEN together. It is in Excel for Microsoft 365.

Examples

  1. The number inside some text

    ABC
    1Note
    2Invoice 4471 paid4471
    3Order AB-2093 sent

    In C2: =REGEXEXTRACT(A2, "[0-9]+") → 4471

    Try this example

  2. A code with a fixed shape

    ABC
    1Note
    2Invoice 4471 paidAB-2093
    3Order AB-2093 sent

    In C2: =REGEXEXTRACT(A3, "[A-Z]{2}-[0-9]{4}") → AB-2093

    Two capital letters, a dash, then four digits.

    Try this example

  3. Ignoring upper and lower case

    ABC
    1Note
    2Invoice 4471 paidInvoice 4471
    3Order AB-2093 sent

    In C2: =REGEXEXTRACT(A2, "invoice [0-9]+", 0, 1) → Invoice 4471

    The last argument, 1, means ignore case. The 0 before it asks for the first match.

    Try this example

Common mistakes

Common questions

How do I extract numbers from text in Excel?

In Microsoft 365, use =REGEXEXTRACT(A2, "[0-9]+") for the first run of digits, and wrap it in VALUE to get a real number. In older versions, use Flash Fill or a combination of MID and FIND.

Try REGEXEXTRACT in the playground

Practise it

Related functions