In Excel, the powerful XLOOKUP function can’t directly handle regex patterns, but you can use a workaround: combine it with VLOOKUP or INDEX + MATCH and apply a regex-enabled formula like IFERROR(REGEXMATCH(...), "No match"). This lets you search for partial matches, wildcards (*), or regex syntax (e.g., [A-Z] for letters) in cell values—without needing a dedicated regex tool. The limitation: Excel’s built-in regex is limited (supports only * and ? wildcards; no lookbehind/lookahead). For full regex power, use a helper column with a Lambda function or VBA. Here’s how to do it step-by-step.
What You'll Need
- A Microsoft Excel file (Excel 365, 2021, or 2019 with XLOOKUP enabled; earlier versions need VLOOKUP/INDEX+MATCH).
- A helper column (or VBA) for regex evaluation—Excel only has basic wildcards (* = any chars, ? = single char). For advanced regex, add a separate function.
- Your dataset with columns:
search_column(values to match against) andtarget_column(values to search in). - Alternative: A helper column to store regex results (e.g.,
=IFERROR(REGEXMATCH(A2, "pattern"), "")).
Step-by-Step
- Prepare your data
- Copy your dataset into a new worksheet (e.g.,
Sheet2). Ensuresearch_columncontains the terms to find andtarget_columncontains the values to search within. - Example:
|Search term|Target values| |---|---| |"SMART ALARM"|"SMART ALARM 2.0", "Home Security", "Security System"| |"GREEN LIGHT"|"GREEN LIGHT", "Traffic Lamp", "Street Light"
- Copy your dataset into a new worksheet (e.g.,
- Use XLOOKUP with a helper column for basic wildcards
- Add a helper column (e.g.,
C2:C) to flag matches. Use:=IFERROR(REGEXMATCH(A2, "*" & B2 & "*"), "No match")ReplaceB2with your search term and"*B2*"wraps it in wildcards for partial matches. - Example: For
A2="SMART ALARM"andB2="Security", the formula becomes:=IFERROR(REGEXMATCH(A2, "*Security*"), "No match")Returns "Yes" if any target contains "Security"; otherwise, "No match." - Drag the formula down to match all rows.
- Add a helper column (e.g.,
- Use XLOOKUP to find matching rows
- In a new column (e.g.,
D2), use:=IFERROR(XLOOKUP(A2, search_column, target_column, "No match", 0), "No match")Replacesearch_columnwith the column of search terms (e.g.,Sheet2!$A$2:$A$100) andtarget_columnwith the values to search (e.g.,Sheet2!$B$2:$B$100). - To combine both steps (helper column + XLOOKUP), use:
=IF(A2="", "", IFERROR(XLOOKUP(ISERROR(REGEXMATCH(A2, "*" & B2 & "*")), "", Sheet2!$A$2:$A$100, Sheet2!$B$2:$B$100, "No match", 0), "No match"))This returns the target value if a match exists, or "No match."
- In a new column (e.g.,
- For regex patterns (advanced)
- Use a helper column to test regex first, then filter results:
=IFERROR(REGEXMATCH(A2, "pattern"), "")Example:=IFERROR(REGEXMATCH(A2, "[A-Z]"), "Yes")finds uppercase letters. - Create a conditional filter:
Data Table > Filter > Advanced Filter, with:- Criteria range: helper column (where regex returns "Yes").
- Copy to: original target column.
- Use a helper column to test regex first, then filter results:
Common Mistakes
- Wildcards don’t work as expected
Excel’s
*and?only match characters literally. For example:REGEXMATCH("test123", "*test*")returns FALSE because*test*expects "test" between*, not anywhere in the string. To fix: UseREGEXMATCH("test123", "test")for exact substring matches. - Case sensitivity
Regex functions in Excel are case-sensitive by default. To match "Smart" or "smart":
=IFERROR(REGEXMATCH(A2, "smart.*", 2), "No match")Add2as the third argument to make it case-insensitive. - Empty results
If your formula returns falsey values (e.g.,
""), useIFERRORor explicit checks to avoid blank cells. Example:=IF(REGEXMATCH(A2, "pattern")<>"" && REGEXMATCH(A2, "pattern"), "Match", "No match") - Performance issues
Complex regex patterns or large datasets slow Excel. Test with smaller data first. For full regex support (e.g., lookarounds), use a helper function or VBA.
Tips
- Limit helper columns
Add a single helper column for regex checks. Avoid recalculating the same pattern repeatedly. Cache results in a separate sheet if needed.
- Use INDEX + MATCH for VLOOKUP compatibility
If formulas fail in older Excel versions, replace XLOOKUP with:
=IFERROR(INDEX(target_column, MATCH(A2, search_column, 0)), "No match") - Test regex patterns in isolation
Create a test column with
=IFERROR(REGEXMATCH(A2, "pattern"), "False")to validate regex syntax before applying it to your data. - Avoid nested functions
For complex logic, extract helper formulas to a named range or a separate sheet. This reduces recalculation time and improves readability.
Troubleshooting
- Formula returns #VALUE!
- Check for typos in regex patterns (e.g., missing quotes around
*). - Verify the search_column contains the exact terms to look up.
- Run a manual test: Type
=REGEXMATCH("text", "pattern")in a blank cell to isolate the regex issue.
- Check for typos in regex patterns (e.g., missing quotes around
- No matches found despite data
- Ensure your helper column returns non-blank values for matches (e.g.,
=IFERROR(REGEXMATCH(...), "Yes")). - Check for hidden characters or formatting (e.g., spaces in cell values). Use
TRIM()to clean data first. - Verify the target_column data isn’t filtered or hidden.
- Ensure your helper column returns non-blank values for matches (e.g.,
- Excel crashes or freezes
- Disable add-ins (File > Options > Add-ins) to rule out conflicts.
- Run a manual calculation (Ctrl+Shift+Enter for array formulas).
- Use a simpler regex pattern to test performance.
- Regex doesn’t support advanced features
- For lookarounds, character classes, or groups, switch to a helper function:
// Pseudo-code for a helper function: Function RegexTest(searchText As String, pattern As String) As Boolean Return Application.WorksheetFunction.RegExpMatch(searchText, pattern) End Function - Alternatively, use VBA to implement full regex (e.g., with
Regexobjects).
- For lookarounds, character classes, or groups, switch to a helper function:
Frequently Asked Questions
Why can’t I use XLOOKUP with regex directly?
Excel’s REGEXMATCH function doesn’t integrate directly with XLOOKUP. You must evaluate regex first (e.g., in a helper column) and use conditional logic to flag matches.
How do I match partial words with regex in XLOOKUP?
Wrap the search term in wildcards: REGEXMATCH(search_cell, "*target_word*"). Example: REGEXMATCH("security", "*security*") finds "security," "Secure," and "Security System."
Can I use regex to find specific case patterns (e.g., "Smart")?
Yes, with the 3 flag: REGEXMATCH(search_cell, "Smart", 3) matches "Smart" but not "smart." To mix cases, use:
REGEXMATCH(search_cell, "smart.*", 2) (flag 2 = case-insensitive).
What if Excel’s regex only supports * and ??
For advanced regex (e.g., [A-Z], ^endswith), use a helper function or VBA. Example VBA function:
Function RegexTest(search As String, pattern As String) As Boolean
Dim regex As Object
Set regex = CreateObject("VBScript.RegExp")
regex.Pattern = pattern
RegexTest = regex.Test(search)
End Function
How do I exclude partial matches in XLOOKUP?
Add a helper column to filter out partial results:
=IF(REGEXMATCH(A2, "exact_pattern"), "Match", "No match")
Then use a filter to show only rows with "Match."
Why does my regex formula return falsey results (e.g., "" or 0)?
Use IFERROR to handle falsey returns: =IFERROR(REGEXMATCH(A2, "pattern"), "No match"). Alternatively, check for explicitly blank strings:
=IF(REGEXMATCH(A2, "pattern") <> "", "Match", "No match")