On Thu, Jul 12, 2001 at 11:21:18AM +0200, Detlef Lindenthal wrote:
> 
> > The result of this is "no match" since the parentheses are being
> > evaluated somehow.  If I remove one of the parentheses in one of the
> > strings, I get an error "unmatched () in regexp".  If I remove all of
> > the parentheses from both strings, I get "match".  Is there a way that
> > I can get grep to consider everything in the strings, including the
> > parentheses, as simple characters?  If I can't, do I need to clean
> > every string before the match, removing parentheses and any other
> > offending characters?  Thanks in advance.

> ##  Do this:

Actually, please don't.


> ###############################
> #!perl -l
> 
> $db_string = "word(1),word(2),word(3)";
> $_ = 'word(1)';       ##  this is what you want to be found
> 
> for $disable_parens(0,1)  {
>   if ($disable_parens)  {
>     s,([()]),\\$1,g  }   ##  won't work without this line "(L)"
>        ##  or instead of the previous line the following 2 lines:
>        ##    s,\(,\\(,g;
>        ##    s,\),\\),g;

You forgot about . * + ? | [ ] { } ^ $ and \


Use quotemeta() or \Q\E instead:

if ($db_string =~ /\Q$web_string/) {
  print "Match!\n";
}

Ronald

Reply via email to