Link to home
Start Free TrialLog in
Avatar of craziest
craziest

asked on

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
Avatar of Kim Ryan
Kim Ryan
Flag of Australia image

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

Avatar of ozo
How are you searching for two words and using AND?
What do you want to do when you ignore AND?
Avatar of Tintin
Tintin

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.
Avatar of craziest

ASKER

https://www.experts-exchange.com/questions/22048966/Perl-Double-quote-problem.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.
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial