Gunnar Hjalmarsson wrote:
Zhao, Bingfeng wrote:
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'.

    $line =~ s/("[^"]*")|abc/$1 ? $1 : 'd'/eg;

You need a non-greedy modifier on that Gunnar:

  $line =~ s/("[^"]*?")|abc/$1 ? $1 : 'd'/eg;

Rob


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to