varun kumar
varun kumar

Reputation: 151

How to use regsub in tcl

I was replacing non alphanumerical character like . \ etc using regsub command and it is not helping. Could you please help me

Text:

This is the new begin.\With old memories

Need to replace ".\" to . Expected:

This is the new begin.With old memories

Tries with

regsub -all {\.\\} $string {\.}

Thanks in advance

Upvotes: 1

Views: 6019

Answers (1)

TrojanName
TrojanName

Reputation: 5355

As Donal said, just use string map e.g.

% set a {This is the new begin.\With old memories}
This is the new begin.\With old memories
% string map {.\\ .} $a
This is the new begin.With old memories

As you can see, I had to escape the backslash with a second backslash.

Upvotes: 1

Related Questions