here is my code so far.
…
regsub -all {~r} $msg {n} msg
…
Are you sure that’s what you want? I can see replacing all of the characters with characters if you just want to look at the data, but it doesn’t look to me like that’s what you’re doing.
Newline terminated messages end segments with “r” and entire messages with “rn”.
Okay, with that out of the way…
You’re running afoul of the Tcl quoting and the regsub command interpretation rules. Generally, {sr} will get you the a string of the literal characters ‘s’ ” ‘r’ if there is only one round of interpretation, but it gets you ‘s’ and a newline if there is another round. The regsub command needs the regular expression string uninterpreted, so this is good for sending it the regex. It quite unfairly doesn’t interpret the replacement string, however. The easy way to get around this is to quote an escaped character with interpolation quotes — e.g. “r”, if you want to get a .
So
regsub -all {~r} $msg “n” msg
will probably do what you are trying to do, but are you sure that’s what you want?