perlfaq6: (cut-n-paste to get the final "-" there)
http://www.perldoc.com/perl5.8.0/pod/perlfaq6.html#How-do-I-match-a-pattern-that-is-supplied-by-the-user-

How do I match a pattern that is supplied by the user? 
Well, if it's really a pattern, then just use 

    chomp($pattern = <STDIN>);
    if ($line =~ /$pattern/) { }  

Alternatively, since you have no guarantee that your user entered a valid regular 
expression, trap the exception this way: 

    if (eval { $line =~ /$pattern/ }) { }  

If all you really want to search for a string, not a pattern, then you should either 
use the index() function, which is made for string searching, or if you can't be 
disabused of using a pattern match on a non-pattern, then be sure to use \Q...\E, 
documented in perlre. 

    $pattern = <STDIN>;
    open (FILE, $input) or die "Couldn't open input $input: $!; aborting";
    while (<FILE>) {
print if /\Q$pattern\E/;
    }
    close FILE;  


Good luck,
.ted


-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]
Sent: Friday, June 06, 2003 10:07 AM
To: [EMAIL PROTECTED]
Subject: regexing AND NOT


Dear cgi-colleagues,

I want to write a cgi-script to allow users to search for strings
in a text. Therefore I use a form offering a field where he / she
can put in what to look for. Instead of asking for a regular expression
I want to give them the possibility of entering something like

        spoon AND NOT spoonful

or

        sun AND NOT sunday suntan sundried

or

        sun mon AND NOT sunday monday suntan sundried

as a search pattern.

Is there a function or a module that translate such
search patterns into a regular expression? Or do I have
to do all the job on my own by rearranging the QUERY_STRING?

If you have any idea, please let me know.

Peter Stahl
University of Wuerzburg 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to