Solved

Ignoring AND in perl

Posted on 2006-11-05
5
227 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
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In this tutorial I will show you how to provide a dynamic RTF document on your website generated with data from your database. For this tutorial you will need Microsoft Word or WordPad, WhizBase and Microsoft Access. In this tutorial I will show …
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…

744 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now