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

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

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

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");
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.