Function Problems

How to Extract a Code from Text Using REGEXEXTRACT and XLOOKUP in Excel

Huma Ashraf ChHuma Ashraf Ch Nov 10, 2026 869 views

Question details

The user wants to extract a specific code pattern from a text string and use it as a lookup value to find related data in another range.

How to Extract a Code from Text Using REGEXEXTRACT and XLOOKUP in Excel
Product
Excel
Device & OS
not provided
Scenario
Cleaning and analyzing data where specific identifier codes are embedded within longer text strings.
Observed behavior
The goal is to accurately isolate the code using regular expressions and pass it to a lookup function to retrieve corresponding information.
Before you start

Ensure your version of Excel supports the newly introduced REGEXEXTRACT function (currently available in Microsoft 365 Beta/Insider channels) and the XLOOKUP function.

Solution 1

Extract the Code Using REGEXEXTRACT

Use a regular expression pattern to isolate the specific code from the surrounding text.

If you only need to pull the code out of a text string without performing any lookup, you can use the REGEXEXTRACT function on its own. This is ideal for cleaning up messy data columns.

1
Select the destination cell

Click on the empty cell where you want the extracted code to appear.

2
Enter the REGEXEXTRACT formula

Input the formula: =REGEXEXTRACT(A1,"(?i)\bY\d-\d{2}-[A-Z]{2}-\d{3}\b") assuming your text is in cell A1.

3
Execute the formula

Press Enter. The formula will extract the matching code from the string.

Understanding the Regex Pattern: The pattern '(?i)' makes the search case-insensitive, '\d' looks for digits, and '[A-Z]' looks for letters. '\b' ensures the match occurs at a word boundary.
Extract and Analyze Data Efficiently

Use WPS Spreadsheet for Advanced Formula Processing

WPS Office provides a powerful, free Spreadsheet tool that supports a vast array of advanced lookup functions, ensuring seamless compatibility with your Excel files and data analysis workflows.

  1. 1. Open your workbook in WPS: Launch WPS Spreadsheet and open your existing .xlsx file containing the text data.
  2. 2. Define your data ranges: Ensure your target lookup data ranges are properly defined and organized.
  3. 3. Apply lookup formulas: Enter your preferred text manipulation and lookup formulas to retrieve the desired data seamlessly.
  4. 4. Save your progress: Save your file in .xlsx format to retain full compatibility across other spreadsheet applications.
Fully compatible with Microsoft Excel (.xlsx) file formats.Supports advanced lookup functions like XLOOKUP for efficient data retrieval.Lightweight and runs smoothly on Windows, Mac, and Linux.Free to use with a familiar, easy-to-navigate tabbed interface.
microsoft office alternative - wps office

Frequently Asked Questions

Why is my REGEXEXTRACT formula returning a #NAME? error?

The #NAME? error typically occurs if your version of Excel does not yet support the REGEXEXTRACT function. It is currently rolling out to specific Microsoft 365 Beta or Insider channels.

Can I use XLOOKUP with partial text matches without Regex?

Yes, if you only need a simple partial match, you can use wildcard characters (* or ?) inside XLOOKUP. However, Regex provides much more precise control over complex text patterns.

What does the "\b" mean in the regex formula?

The "\b" represents a "word boundary". It ensures that the formula only matches the exact standalone code pattern and prevents accidental extraction from a longer string of combined characters.