jeudi 3 novembre 2016

Given a set of string patterns, find which ones match a particular string

I have an array of known patterns with optional wildcards. For example this 5 elements array:

ab*e
hkl
abcd*
ab
sdfs?f

Now I need to find the elements within the array that match an arbitrary string.

This can be solved with regular expression by returning all the matched pattern in the array, but it is too slow when my patterns array has thousands of patterns, and I need to perform this check very fast for a large number of arbitrary strings.

I'm looking for some sort of hashing to the patterns array (could be slow as it only happens once), which makes the search of matched patterns to a gives string significantly faster.

In the example above if I'm looking for all matched patterns for abcde I would get

ab*d
abcd*

Aucun commentaire:

Enregistrer un commentaire