Re: How to match a token not be quoted?
- From: noreply@xxxxxxxxx (Gunnar Hjalmarsson)
- Date: Tue, 29 Jan 2008 06:18:51 +0100
Rob Dixon wrote:
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;
Why would I need that? Are you mixing up [^"]* with .* ?
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
.
- Follow-Ups:
- Re: How to match a token not be quoted?
- From: Rob Dixon
- Re: How to match a token not be quoted?
- References:
- How to match a token not be quoted?
- From: Bingfeng Zhao
- Re: How to match a token not be quoted?
- From: Gunnar Hjalmarsson
- Re: How to match a token not be quoted?
- From: Rob Dixon
- How to match a token not be quoted?
- Prev by Date: RE: How to match a token not be quoted?
- Next by Date: Re: file.db VS filedb
- 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
|