List:General Discussion« Previous MessageNext Message »
From:Adrian Phillips Date:July 14 2000 2:15pm
Subject:Re: Regexp using perl
View as plain text  
>>>>> "Marcus" == Marcus  <lists@stripped> writes:

    Marcus> 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";

    Marcus> Thanks for all your replies so far.  What I don't
    Marcus> understand is why quote() is necessary?  Would anybody
    Marcus> mind explaining just so I also understand what I'm doing
    Marcus> here?

    Marcus> This is what's wrong: When I want to match the 'title'
    Marcus> field and I input the exact string in the field
    Marcus> (eg. 'Perl'), I get a 100% match using 'LIKE $string', and
    Marcus> it works.  However, as soon as I input a part string
    Marcus> (eg. 'erl') , I get an error.  Why does it work with the
    Marcus> exact match?

    Marcus> I've tried '%$string%' too, as stated in the Mysql
    Marcus> manual. No luck.  Any ideas what I'm missing here?

    Marcus> Thanks,

    Marcus> Marcus Friedlaender

man DBI - look for placeholders and save yourself some of this
trouble.

Sincerely,

Adrian Phillips
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