bug-gawk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [bug-gawk] Issue #Q5: regexp: gsub: symbol `&' in replacement parame


From: Davide Brini
Subject: Re: [bug-gawk] Issue #Q5: regexp: gsub: symbol `&' in replacement parameter
Date: Tue, 6 Nov 2012 15:51:40 +0100

On Tue, 6 Nov 2012 16:25:21 +0200, Denis Shirokov <address@hidden>
wrote:

> Hi!
> 
> Another strange regexp issue:
> 
> Q5:
> If character `&' is present in parameter `replacement' of gsub
> function, then this character will be replaced by string that actually
> matches to regular expression:
> 
> >gawk --version
> GNU Awk 4.0.1
> Copyright (C) 1989, 1991-2012 Free Software Foundation.
> 
> >type Q5.gwk
> 
> BEGIN{
>         a="abcdef"
>         print "`" a "'"
>         gsub(/cd/,"C&D&Z",a)
>         print "`" a "'" }
> 
> >gawk -f Q5.gwk
> `abcdef'
> `abCcdDcdZef'
> 
> 
> ------------------------------------------------------
> (file Q5.gwk attached)
> 
> As you can see - string `cd' matched by regular expression /cd/ was
> been replaced by `CcdDcdZ' - not by `C&D&Z'.
> It looks like this symbol has some special meaning in replacement string.
> 
> If this is `by design' then what else characters have special
> meanings? Is there a way to work in GSUB with parts of matched strings
> like in gensub function?

It is by design, for the scaring details read here:

http://www.gnu.org/software/gawk/manual/gawk.html#Gory-Details




-- 
D.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]