[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[bug-gawk] Issue #Q5: regexp: gsub: symbol `&' in replacement parameter
From: |
Denis Shirokov |
Subject: |
[bug-gawk] Issue #Q5: regexp: gsub: symbol `&' in replacement parameter |
Date: |
Tue, 6 Nov 2012 16:25:21 +0200 |
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?
Q5.gwk
Description: Binary data
- [bug-gawk] Issue #Q5: regexp: gsub: symbol `&' in replacement parameter,
Denis Shirokov <=