Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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

In reply to RegEx for users who dont know RegEx by dimar

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2024-04-19 21:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found