Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language


 
 
Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

TCL(Tool Command Language) Scripting

regsub help


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}

Regards
Cloud

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

On May 25, 3:13 pm, suchenwi <richard.suchenwirth-

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

Sorry again
Regards
Cloud

On 25 Mai, 14:56, CloudStrife <santosh.iitm2@gmail.com> wrote:

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

On May 25, 6:00 pm, suchenwi <richard.suchenwirth-

Hi suchenwi,
Thanks a lot. I did not know the reason for the existence of {} around
\1.
This solves the problem
Thanks once again

Regards
Cloud

suchenwi wrote:
> Again, a simpler example to demonstrate:
>  % set x y; regsub (b) abc \\1$x
>  abyc

When these sorts of things get complex, it's easier to use [format] to
help out, like this:
   regsub {.*(demo).*} $line [format {\1%s} $mod] n_line

Though for this particular case, I'd actually do this:
   set n_line [string map {demo demonstrate} $line]

Donal.

CloudStrife <santosh.iitm2@gmail.com> writes:
> regsub {.*(demo).*} $line {\1$mod} n_line

You got the brace issue solved, but there is still the
problem of excessive matching.  Here you don't replace
the "demo", but instead discard *everything else* (.* .*)
keep "demo" (\1) and append "demonstrate" ($mod).  Thus,
any line with "demo" in it will result in "demodemonstrate".

I suspect you were looking for

  regsub {\ydemo\y} $line $mod new

--
Donald Arseneau                          a@triumf.ca

Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc