Saskia Hermans
Saskia Hermans

Reputation: 19

Removing variable text between braces from a string

I need to remove all text between the braces { and } (the braces included) and I don't know in advance which text is between them nor how long the text is.

Example:

AA {some text here } BB { some other text here } CC

should become:

AA BB CC

Upvotes: 0

Views: 71

Answers (1)

glenn jackman
glenn jackman

Reputation: 246807

I'd use regsub here:

set filtered [regsub -all {\{.*?\}} $s ""]

Or, treat the string as a list of lists, and remove the sublists is length > 1

set filtered [lmap word $s {if {[llength $word] == 1} then {set word} else continue}]

Upvotes: 1

Related Questions