heyhey
heyhey

Reputation: 301

Split with multiple spaces and lists

I have this kind of line :

AA      BB  CC dd {ee ff} gg

I would like to split this line but with keeping the list like :

AA BB CC dd {ee ff} gg

so I tried split but I got multiple {} due to the multiple space between AA and BB

I triied also

set splitted_line [regexp -all -inline {\S+} $list]

but this command splits the list in {ee and ff}

What should I do to split my line properly ?

Upvotes: 1

Views: 184

Answers (1)

Donal Fellows
Donal Fellows

Reputation: 137807

If your line really will have {brace-quoted} words in it, you can probably get away with just treating it as a Tcl list directly. In that case, the first port of call for “cleaning it up” is to use lrange:

set splitted_line [lrange $list 0 end]

This will also convert a few other things, such as "double-quoted" words; I don't know if that's what you want.
Example session:

% set example {A   BB  CCC  {dd    ee} "ff $gg"    }
A   BB  CCC  {dd    ee} "ff $gg"    
% lrange $example 0 end
A BB CCC {dd    ee} {ff $gg}

Upvotes: 2

Related Questions