Aspen
Aspen

Reputation: 91

How to split a text(list) into sections(list) by a starting pattern in tcl

For example, my text is :

Block 1:
   xxxxxx xxxx
   xxxxxx xxxx
   xxxxxx xxxx
Block 2:
   xxxxxx xxxx
   xxxxxx xxxx
   xxxxxx xxxx
Block 3:
   xxxxxx xxxx
   xxxxxx xxxx
   xxxxxx xxxx

I want to split the by the different blocks, in tcl. E.g:

{Block 1:
   xxxxxx xxxx
   xxxxxx xxxx
   xxxxxx xxxx}
{Block 2:
   xxxxxx xxxx
   xxxxxx xxxx
   xxxxxx xxxx}
{Block 3:
   xxxxxx xxxx
   xxxxxx xxxx
   xxxxxx xxxx}

Any way to make this work? Thanks!

Upvotes: 0

Views: 143

Answers (1)

schlenk
schlenk

Reputation: 7257

Try the tcllib `textutil::splitx`` command. (see http://core.tcl.tk/tcllib/doc/trunk/embedded/www/tcllib/files/modules/textutil/textutil.html#8)

It can split text based on a regular expression.

Upvotes: 2

Related Questions