http://www.perlmonks.org?node_id=417149

dimar has asked for the wisdom of the Perl Monks concerning the following question:

Goal: There is a simple script that searches through flat text files based on a simple 'query string.' The query string is supplied by the user. The goal is to allow the user to supply 'wildcards' in her query string. The syntax for queries is very minimal (i.e., dumb flat search for a string with no fancy boolean operators, no filtering capabilities, no letter-case distinctions).

Question:What is the best way to process a user-supplied search 'query' such that a user is allowed to include simple wildcard characters. (eg not full-blown RegEx) For example, if the user supplies:

i*ation
The script should return all matching items in the flat file:
invitation information Isolation InFlaTiOn IATION
But the script should not return:
In our nation it requires concentration fiat ionizing

Is the best approach simply to take the user input and translate that into a full-blown RegEx, and then use that? Devising a RegEx that meets the requirement is no problem, but it seems like a potential red-flag to be post processing a user-supplied into a RegEx for some reason. Perhaps there is a better way to approach this.


Update -- modified example positive match that was intended to represent a false-positive match; re: The Mad Hatter