AhoCorasick
AhoCorasick copied to clipboard
Wildcard matching
Do you think it would be easy to add wildcard matching to this? Any tips how it might be achieved?
Thinking * for any number of characters, and ? For a single character.
Unfortunately, it's not easy to extend the algorithm to wildcards. Perhaps you could search for all the non-wildcard substrings of your patterns and then perform additional checks to see if the matched substrings are in the correct positions. For example, if you have "ab*cd*ef"
, then search for "ab"
, "cd"
, "ef"
and if there's a match then check if the matched indexes are in the correct order, meaning you'd have a match for the whole wildcard pattern.
Thanks thats a good idea, we can try exploring that.