George_Sherston has asked for the wisdom of the Perl Monks concerning the following question:
my @KeysNeed; my @KeysAvoid; my @Keys; my $keywords = $q->param('keywords'); # get the phrases out of $keywords and store them: while ($keywords =~ s/([+-]*)["'](.*?\W?.*?)["']//) { my $cat = $1; my $keyword = $2; $keyword =~ s/\s+/ /g; if (defined $1 and $1 eq '+') { push @KeysNeed, $keyword if $keyword; } elsif (defined $1 and $1 eq '-') { push @KeysAvoid, $keyword if $keyword; } else { push @Keys, $keyword if $keyword; } } # strip surplus whitespace: $keywords =~ s/\s+/ /g; # get the remaining words out of $keywords and store them: my @keywords = split /\s+/, $keywords; for (@keywords) { s/^([+-])*//; s/[^a-zA-Z0-9 ]//g; if (defined $1 and $1 eq '+') { push @KeysNeed, $_ if $_; } elsif (defined $1 and $1 eq '-') { push @KeysAvoid, $_ if $_; } else { push @Keys, $_ if $_; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Regexing my Search Terms
by merlyn (Sage) on Jan 07, 2002 at 19:51 UTC | |
|
Re: Regexing my Search Terms
by chipmunk (Parson) on Jan 07, 2002 at 20:44 UTC | |
by George_Sherston (Vicar) on Jan 07, 2002 at 22:32 UTC | |
|
Re: Regexing my Search Terms
by joealba (Hermit) on Jan 07, 2002 at 22:24 UTC | |
|
Re: Regexing my Search Terms
by Aristotle (Chancellor) on Jan 07, 2002 at 23:09 UTC | |
|
Re: Regexing my Search Terms
by dreadpiratepeter (Priest) on Jan 09, 2002 at 18:48 UTC |