Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Previous issue about removing curly braces in TCL with regsub command

Status
Not open for further replies.

Bill Guy

Programmer
Nov 17, 2018
1
US
I was trying to figure out how to remove curly braces from a string in TCL.

I ran across thread287-1105238 which stated that one user tried the following and it didn't work:

regsub -all {[\{]} $sToken "" sToken

but another user did have the above work.

My TCL intepreter did not work with the above, but the following did work for me ... and I wanted to remove the left and right curly brace anyway.

regsub -all {[\{|\}]} $sToken "" sToken

The right curly brace allowed the TCL interpreter to see it as a valid construct and the execution was as expected.

finale(tcl)> set sToken "{{something}}"; echo $sToken
{{something}}
finale(tcl)> regsub -all {[\{|\}]} $sToken "" sToken; echo $sToken
something

Hope that helps someone else.

Bill
 
Hi

Bill said:
... and I wanted to remove the left and right curly brace anyway.

regsub -all {[\{|\}]} $sToken "" sToken
Actually that regular expression matches "{", "|" and "}", so [tt]regsub[/tt] will replace occurrences of all 3.

To replace only "{" and "}" you need :
Code:
[b]regsub[/b] [teal]-[/teal]all [teal]{[\{\}]}[/teal] [navy]$sToken[/navy] [i][green]""[/green][/i]

[gray]# or[/gray]

[b]regsub[/b] [teal]-[/teal]all [teal]{\{|\}}[/teal] [navy]$sToken[/navy] [i][green]""[/green][/i]

Feherke.
feherke.github.io
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top