loki has asked for the wisdom of the Perl Monks concerning the following question:

hi all, i have a doubt on this regular exp can anyone explain me clearly.. actualy i am trying to extract the multiple conditions inside while and if... am using perl 5.8.6 windows XP.......

my perl code sampled: my $count = 0; foreach my $condition (@conditions) { $count++; my ($open,$close) = $condition =~ /( (?: [(] | \s )* ) (.*) /msx; print "$open $count $close"; }

and my C code

while ( ( 1 condition A && 2 condition B )&& ( 3 condition C 4 condition D ) )

and am facing the problem when i have a while loop like this

while ( (condition A) && (condition B) )
my desired output has to be....
while ( 1 (condition A) && 2 (condition B) )
but it prints has...
while ( ( 1 condition A) && ( 2 condition B) )

can anyone help me with the regex pls to get my desired output?

Replies are listed 'Best First'.
Re: doubt on assertion regex
by Anonymous Monk on Jan 20, 2010 at 16:04 UTC
    You have print "$open $count $close"; and you state that you want the number to preceed the parenthesis.

    So use print "$count $open$close";

      no its wrong... it will print as
      while 1( 2(condition A)&& 3(condition B) )
      which is not desired....
        My code prints a space between the numeral and the opening parenthesis. Show what code you're actually using, because it's not the same.