bauersa
@siemens.com> wrote:
> On 25 Mai, 14:56, CloudStrife <santosh.iitm2
@gmail.com> wrote:
> > On May 25, 3:13 pm, suchenwi <richard.suchenwirth-
> > bauersa@siemens.com> wrote:
> > > On 25 Mai, 12:09, CloudStrife <santosh.iitm2@gmail.com> wrote:
> > > > The follwing doesnot work and I would like to have a work around
> > > > set line "This is a test line to demo the use of regsub"
> > > > # Replace demo with demonstrate.. here I am doing it by concatenating
> > > > 'demo' and 'nstrate' ...
> > > > regsub {.*(demo).*} $line {\1nstrate} n_line
> > > > This can be done by
> > > > regsub {\sdemo\s} $line demonstrate n_line
> > > > But this is not wat i want I want a solution to make this kind of
> > > > things work ----- {\1nstrate}
> > > Your .* are too many - regexps are normally unanchored to left and
> > > right anyway. Compare (with simpler test cases):
> > > 47548 % regsub (b) abc {\1d}
> > > abdc
> > > 4698 % regsub .*(b).* abc {\1d}
> > > bd
> > Hi all,
> > Sorry to all. As my question wasnt exactly what I wanted to know. Here
> > is the question reframed...
> > How to do the following:
> > set line "This is a test line to demo the use of regsub"
> > set mod nstrate
> > # Replace demo with demonstrate.. here I am doing it by concatenating
> > 'demo' and 'nstrate' ...
> > regsub {.*(demo).*} $line {\1$mod} n_line
> Ah, ok. You want to use a variable in the replacement string. This is
> a Tcl "syntax" issue: Braces protect the \1, but also the $mod. For
> partial protection, use e.g.
> regsub {.*(demo).*} $line \\1$mod n_line
> i.e. escape the backslash but not the $mod. Again, a simpler example
> to demonstrate:
> % set x y; regsub (b) abc \\1$x
> abyc
Hi suchenwi,