List:General Discussion« Previous MessageNext Message »
From:Gerald Clark Date:July 12 2000 7:21pm
Subject:Re: Regexp using perl
View as plain text  
Marcus wrote:

> On 09.07.00 at 15:28 Wesley Darlington wrote:
> > my $search_regex = $dbh->quote($search_string);
> >    $search_regex =~ s/\%/\\\%/g;    # Escape % signs too
> >    $search_regex =~ s/^'/'\%/;   # Add a percent at the beginning...
> >    $search_regex =~ s/'%/\%'/;   # ...and at the end
> > my $query = "SELECT Text FROM Table WHERE Text LIKE $search_regex";
>
> Thanks for all your replies so far.
> What I don't understand is why quote() is necessary?
> Would anybody mind explaining just so I also understand what I'm doing
> here?
>
> This is what's wrong:
> When I want to match the 'title' field and I input the exact string in
> the field (eg. 'Perl'), I get a 100% match using 'LIKE $string', and it
> works.
> However, as soon as I input a part string (eg. 'erl') , I get an error.
> Why does it work with the exact match?
>
> I've tried '%$string%' too, as stated in the Mysql manual. No luck.
> Any ideas what I'm missing here?
>
> Thanks,
>
> Marcus Friedlaender

Try "%$string%" instead.
The single quote will prevent variable expansion.


Thread
Regexp using perlMarcus9 Jul
  • Re: Regexp using perlWesley Darlington9 Jul
    • Re: Regexp using perlMarcus12 Jul
      • Re: Regexp using perlWesley Darlington13 Jul
  • Re: Regexp using perlJerome Abela10 Jul
  • Re: Regexp using perlColin Faber10 Jul
  • Re: Regexp using perlGerald Clark12 Jul
  • Re: Regexp using perlAdrian Phillips14 Jul