Re: How to match a token not be quoted?
- From: rob.dixon@xxxxxxx (Rob Dixon)
- Date: Tue, 29 Jan 2008 02:52:16 +0000
Zhao, Bingfeng wrote:
Hello,
I want to a cure regex that match following requirements: given $line =
'abc abc "abc abcc" abcc', I want to replace all instances of "abc" that
not in quotation with, say 'd', so I expect I get 'd d "abc abcc" dc'.
What should I write my regex? I try some and referred cook book also, no
solution. Thanks in advance.
The program below does what you require.
HTH,
Rob
use strict;
use warnings;
my $str = 'abc abc "abc abcc" abcc';
my @str = split /("[^"]*?")/, $str;
for (my $i = 0; $i < @str; $i += 2) {
$str[$i] =~ s/abc/d/g;
}
$str = join '', @str;
print $str, "\n";
**OUTPUT**
d d "abc abcc" dc
.
- References:
- How to match a token not be quoted?
- From: Bingfeng Zhao
- How to match a token not be quoted?
- Prev by Date: Re: How to match a token not be quoted?
- Next by Date: Re: How to match a token not be quoted?
- Previous by thread: Re: How to match a token not be quoted?
- Next by thread: Re: How to match a token not be quoted?
- Index(es):
Relevant Pages
|