• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 251
  • Last Modified:

Ignoring AND in perl

i want to search for two words and inbetween them i use AND
whats the code for ignoring AND?
any help would be appriciated,thanx
0
craziest
Asked:
craziest
1 Solution
 
Kim RyanIT ConsultantCommented:
Do you mean you want to serach for the patter 'word1 AND word2' ?
You just say
if ( str =~ /word1 AND word2/ )
{
    print "Found word1 word2\n";
}

0
 
ozoCommented:
How are you searching for two words and using AND?
What do you want to do when you ignore AND?
0
 
TintinCommented:
I'll interpret the question as having

word1 AND word2

and wanting to match them and "ignoring" the AND.

$string='word1 AND word2';
if ($string ~= /word1\s+\w+\s+word2/i) {
  print "Matched\n";
}

The above matches word1 followed by one or more whitespace, one or more word characters and one or more whitespace followed by word2.  The match is case insensitive.

There's loads of other combinations, but you need to be much more specific with your requirements.
0
 
craziestAuthor Commented:
http://www.experts-exchange.com/Web/Web_Languages/CGI/Q_22048966.html
thats my code,thnx to ozo i managed to get the double quotes.now i mean if someone types AND inbetween two words it should look for both the words.Tintin is almost there but i didnt know how it would be on my code.thanks.
0
 
ozoCommented:
@cut = grep{defined}$search =~ /\bAND\b|(\w+)|"([^"]+)"/g;
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Tackle projects and never again get stuck behind a technical roadblock.
Join Now