How can I regsub pattern to another pattern
set a "how1how ku2ku how2how" ; regsub "how*how" $a "oo_how\*how_oo"
I want all names "how(num)how" will be swap to the same name with prefix and suffix but the above regsub now work for me
1 Answer
A capture group followed by a backreference usually:
% set a "how1how ku2ku how2how"
how1how ku2ku how2how
% regsub -all {how([0-9]+)how} $a {oo_how\1how_oo}
oo_how1how_oo ku2ku oo_how2how_oo
Following the comments, I think that maybe what you are after is something like this?
set word "how"
set a "how1how ku2ku how2how"
regsub -all [format {%s([0-9]+)%s} $word $word] $a [format {oo_%s\1%s_oo} $word $word]
format allows some substitution where strings %s would be substituted with the provided parameters.