How to substitute the value with in double quotes in perl?

Hi,

I have string like this:


$str=' DNA OR ("rna AND binding AND protein")';

I just wanted to substitute AND with a blank. How can i do that?

I want the output like this:


$string= DNA OR ("rna binding protein")

How can i substitute the AND operator within the double quotes with a NULL value in perl?

Regards
Vanitha

In this case you can use just:

$str =~ s/AND//g;

If you want to be more specific and substitute only the matching text inside double quotes you could use something like this (assuming all double quotes are balanced):

#!/usr/bin/perl

use warnings;
use strict;


my ($str, $x) = 'AND DNA OR ("rna AND binding AND protein")';

$str =~ s/(?<=")([^"]*)(?=")/($x = $1) =~ s|AND||g;$x/ge;

print $str, "\n";

Sample output:

% ./s  
AND DNA OR ("rna  binding  protein")

Hi,

Thanks for the reply.

It should not substitute AND everywhere only inside a double quoted string but above example it is substituted in the beginning. ( AND DNA OR ("rna binding protein")) which is not correct.

The requirement is the AND operator should be substituted only where there is a double quoted string.

How can i do that?

Regards
Vanitha

In my second example I did just that, or I'm missing something?