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.
You wrote: Using my routine modified as above, I found no errors, even on the 10000 row Data table.
If you open my text file as is, you can see that I got errors and the error is always the same:
Expression.Error: The operation could not be completed because the enumeration did not contain enough elements.
Even with your updated code, I get a lot of wrong results:
As you can see I have a German (DE) system, I that an issue for RefEx?
Which locale do you have?
Andreas.