I have a database full of ModelNumbers that I want a user to be able to search for. The tricky part is that some of the model numbers have lots of funny characters including:
* - Alphanumeric wildcard # - Numeric wildcard (AB,CD) - List of options
So for example model number 1234#*(AB,CD)
The following searches should return this model number:
- 12341ACD - full part number with options
- 12341A - "starts with" with some wildcards filled in.
- 2341 - "contains" with some wildcards filled in.
I have attempted to use regular expressions. I have written some code to convert these wild card characters into regular expressions; that code was relatively easy and I have good unit tests for it. A regular expression of
1234[0-9]?[A-Z0-9]?(AB|CD)? will work for the first search string; the regex will not for #2 and #3 since it only matches a part of the pattern.
I tried using PCRE with partial matching, but the intent for that is for evaluating the regex as a user types (from left to right), so the partial match only works for #1 and #2.
I do not want to use fuzzy matching. I am trying to return only specific matching model numbers. The results of the search will represent "qualified" model numbers, so I cannot return model numbers that are only "close" to the search text.
How can I do this? I'm not looking for help with the code, but maybe instead for a strategy. Is there some way to use a regex with only a "contains" type of match? Should I use regex at all for this?