Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Ignoring AND in perl

Posted on 2006-11-05
5
Medium Priority
?
243 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 85

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 85

Accepted Solution

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

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This tutorial will discuss the log-in process using WhizBase. In this article I assume you already know HTML. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you might look at some of my other articles abo…
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…
The viewer will learn how to count occurrences of each item in an array.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

824 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