Theoretical Physics
Theoretical Physics

Reputation: 1

Putting punctuation to the right position in a text (in Tcl)

I have a text which has slightly been modified by a tcl code. Now it looks as follows:

word1 word2 word3 word4 , word5 word6 word7 word8 . word9 , word10 word11 word12 ; word13 word14 word15...

As you can see, characters like . or , are removed from the words. I would like to put them into their original position, that is

word1 word2 word3 word4, word5 word6 word7 word8. word9, word10 ...

As I work with tcl 8.0, I would like to use the regsub-command if possible. (string replace is not implemented in tcl 8.0)

Any help is welcome.

Thanks in advance!

Upvotes: 0

Views: 71

Answers (1)

glenn jackman
glenn jackman

Reputation: 247042

Try

regsub -all {[[:space:]]+([[:punct:]])} $text {\1} new_text

Thanks for your comments folks

regsub -all -nocase {[ \t]+([^a-z0-9])} $text {\1} new_text

Upvotes: 1

Related Questions