mark2atsafe
Instructor
I have a string, for example...
{attr 1} {a b c} attr2 abcd attr3 {a b c}
I need to replace all spaces with special characters (say !!!) but ONLY those spaces inside braces.
So in the above I need...
{attr!!!1} {a!!!b!!!c} attr2 abcd attr3 {a!!!b!!!c}
Any suggestions? At the moment I'm using...
...the problem being that on the second pass the regexp matches with "{attr!!!1} " giving "{attr!!!1}!!!{a!!!....."
What I need is a function that says regsub (but only up to the next } char)! Is there such a component in regsub? And is it possible to do all this inside a single command, without using the loop?
Any help would be greatly appreciated, since I've been banging my head on the wall over this one for ages.
Thanks!
Mark I
PS - What I'm actually looking for is an output of...
attr 1,a b c,attr2,abcd,attr3,a b c
...but if I can flag the correct space characters I can work out the rest OK. Of course, if there is an all in one solution, so much the better.
{attr 1} {a b c} attr2 abcd attr3 {a b c}
I need to replace all spaces with special characters (say !!!) but ONLY those spaces inside braces.
So in the above I need...
{attr!!!1} {a!!!b!!!c} attr2 abcd attr3 {a!!!b!!!c}
Any suggestions? At the moment I'm using...
Code:
while {[regexp (\{)+(.)+( ) $_string] !=0} {
regsub -all (\{)+(\[^ \])+( ) $_string {&!!!} _string2
}
...the problem being that on the second pass the regexp matches with "{attr!!!1} " giving "{attr!!!1}!!!{a!!!....."
What I need is a function that says regsub (but only up to the next } char)! Is there such a component in regsub? And is it possible to do all this inside a single command, without using the loop?
Any help would be greatly appreciated, since I've been banging my head on the wall over this one for ages.
Thanks!
Mark I
PS - What I'm actually looking for is an output of...
attr 1,a b c,attr2,abcd,attr3,a b c
...but if I can flag the correct space characters I can work out the rest OK. Of course, if there is an all in one solution, so much the better.