Forum Discussion
Wildcard Matching 2024
You write: "when calling RegEx, the function often fails with an error.".
Using my routine modified as above, I found no errors, even on the 10000 row Data table.
And I had removed your line in your test code that was filtering out the errors.
Here is my current function code: I have it set to case-insensitive, but it could be changed so that the case sensitivity is an option
(text,regex)=>
let
regList = Text.ToList(regex),
translate =
List.ReplaceMatchingItems(regList, List.Zip({{"*","#","?","."}, {".*","[0-9]",".","\\."}})),
reg = "\\b" & Text.Combine(translate,"") & "\\b",
fx = Web.Page(
"<script>
var x='"&Text.From(text)&"';
var y=new RegExp('"& reg &"','i');
var b=x.match(y);
document.write(b);
</script>")[Data]{0}[Children]{0}[Children]{1}[Text]{0}
in
fx <> "null"
and here is the current "test" code: (with the #"Replaced Errors" step commented out)
let
Source = Data,
#"Invoked Custom Function" = Table.Buffer(Table.AddColumn(Source, "fnRegExWildcard", each fnRegexExtr([text], [mask]))),
//#"Replaced Errors" = Table.ReplaceErrorValues(#"Invoked Custom Function", {{"fnRegExWildcard", "Error"}}),
#"Added Custom" = Table.AddColumn(#"Invoked Custom Function", "Correct", each [fnLIKE]=[fnRegExWildcard])
in
#"Added Custom"
I would appreciate data that produces the errors.
Hi Ron,
I tested your routine on Win10 English (USA) system and get a lot of errors and wrong results.
It seem I got my routine working, I have to test many regular pattern during the next days, fingers crossed.
PQ function here:
https://www.dropbox.com/scl/fi/nw4nwwxa4g99dvbm0vl0s/fnCompareWildcards.pq?rlkey=kw8ze79eytk7uzdpm4miugwdk&dl=1
Test file here:
https://www.dropbox.com/scl/fi/hnv86prqiewyajra5h0yr/CompareRegEx.xlsm?rlkey=70ge7534tuugp17ottiw2wwya&dl=1
Seems my routine is several 1000% faster then RegEx!
Andreas.