0

Hi,

I have a string like

"The quick brown fox jumps over the lazy dog" (or longer)

I have to search through this string using boolean operators like

"quick AND brown OR fox"

mantaining the logical order, so "quick AND (brown OR fox)".

(consider that the search string can be longer with n search options).

What's the strategy?

How to proceed with this?


With regards
Vanditha

3
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by raul15791
0

Open an editor and start writing code and testing the results is how you start. School work?

HI

I tried doing like this

$str=quick AND (brown OR fox);

@query=split(/ OR /,$str);

foreach(@query)
{
    if($_=~/AND/)
  {
    @andarray=split(/ AND /,$_);
   //perform matching
 }
}

But this works for small condition but if multiple paranthesis are there i am finding difficult?

for eg:- (brown AND (fox OR well)) like this many boolean conditions..

I don't know what should be done for this?

With regards
Vanditha

0

Can we use multiple regular expression like this??

#!/usr/bin/perl/
#matching.pl

use warnings;
use strict;

my $temp_string = "The quick brown fox jumps over the lazy dog";
my $true = 0;

if ($temp_string =~ /\bbrown\b/ || /\bfox\b/)
{
     if($temp_string =~ /\bquick\b/)
     {
          $true = 1;
     }
}

if($true == 1)
{
     print ("The string contains the logical quick AND brown OR fox");
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.