I assume that you match words or parts of words. You want the search terms, separated by spaces, to limit the search results, and it seems that you intend to return only those records that contain all the words that the user provides. And you mean the wildcard character * to stand for 0 or more characters in the corresponding word.
For example, if a user searches for the words term1 term2 , you intend to return only those elements that have both the words term1 and term2 . If the user searches for the word term * , it will match any word starting with term .
There are suitable regular expressions that are equivalent to this search language and can be generated from it.
A simple example, the word term , can be claimed in regex by conversion to \bterm\b . But two or more words that must coincide in any order require statements of opinion. Using the extended syntax, the equivalent regular expression:
(?= .* \b term1 \b ) (?= .* \b term2 \b )
An asterisk wildcard can be specified in a regular expression with a character class followed by an asterisk. The character class determines which letters you consider to be part of the word. For example, you may find that [A-Za-z0-9]* matches the score.
In short, you can be satisfied if you convert an expression, for example:
foo ba* quux
in
(?= .* \b foo \b ) (?= .* \b ba[A-Za-z0-9]* \b ) (?= .* \b quux \b )
This is a simple search and replace question. But be careful to clear the input line to avoid injections by removing punctuation, etc.
source share