I have an expression like /a/b/c.d/f.
I need all the characters in between / or .. When I tried to split them using split command, I am getting the result as {} a b c d f {}. How can I avoid these null strings? Is there a way to get this done using regsub?
I have an expression like /a/b/c.d/f. I need all the characters in between /
Share
Those empty strings (they’re not nulls) are saying that there are separators at the start and end of the string. You’d also get them if you had two separators next to each other; the
splitcommand is really oriented towards dealing with records, not words in more “ordinary” text.One of the easiest methods of extracting the non-separator parts (note: I’ve flipped the problem on its head here) is to use
regexp -all -inline, which will return a list of all the matched things:Be slightly careful with this: if you have capturing sub-regexps, they’ll also be returned when you’re using the
-all -inlineoptions.