Solved

Ignoring AND in perl

Posted on 2006-11-05
5
236 Views
Last Modified: 2013-12-25
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
Comment
Question by:craziest
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 19

Expert Comment

by:Kim Ryan
ID: 17878239
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
 
LVL 84

Expert Comment

by:ozo
ID: 17878522
How are you searching for two words and using AND?
What do you want to do when you ignore AND?
0
 
LVL 48

Expert Comment

by:Tintin
ID: 17878555
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
 
LVL 3

Author Comment

by:craziest
ID: 17879755
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
 
LVL 84

Accepted Solution

by:
ozo earned 70 total points
ID: 17879793
@cut = grep{defined}$search =~ /\bAND\b|(\w+)|"([^"]+)"/g;
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to make a simple HTML bar chart with the usage of WhizBase, If you want more information about WhizBase please read my previous articles at http://www.experts-exchange.com/ARTH_5123186.html (http://www.experts-ex…
It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

632 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question