How to use regex with strings containing special characters
I'm using XLOOKUP with a regular expression and values that contain an asterisk (*). I can use exact matches, but I want to be able to do partial matches and seem to require a regular expression.
Using a partial match with "exact or next smallest/largest" as the 5th parameter to XLOOKUP produces unwanted results.
In the above, the same formula is in each cell of column D. It uses the first 6 characters of the value in A to search B and, if a match is found, return the adjacent value in C. Otherwise, return "Not found".
At D3, the value in A3 is used in the expression and the asterisk is treated as a wild card, so it matches the row above instead of the row I want it to.
At D5, the asterisk being treated as a special character means it doesn't match the literal asterisk in B4.
One option is to do a search and replace on the value in A so that "*" becomes "\*" (i.e. quote the *) and the asterisk is treated as a literal and not a special character.
This "works", but it means I have to quote any special characters (+, ?, [, ] and so on) so they're treated as literals in the regular expression. I'm dealing with financial transaction data so the character set in the data is pretty limited and at the moment I've only come across asterisks. However I expect other characters may appear in future causing difficult to find bugs.
I could create copies of column A and B with special characters removed, but that seems clumsy.
Is there any other way to tell REGEX to ignore special characters in the regular expression string?