Reputation: 749
I need to process a random string which has the character ".." in-between. Like the one shown below
a..b/c..de/f-g..xyz..abc..def..123..
How can I get the data between these ".." using regexp?( this string can be of any length and I need to get each intermediate data set for further processing). Please guide me with this.
Thanks!
Upvotes: 2
Views: 169
Reputation: 137787
One tool to consider for this sort of thing, especially if the splitting term is more complex than the one in the question, is the textutil::split
package in Tcllib. That lets you split strings by regular expression, like this:
package require textutil::split
set sample "a..b/c..de/f-g..xyz..abc..def..123.."
set RE {\.\.}; # “.” is an RE metacharacter, and so needs to be escaped
set pieces [textutil::split::splitx $sample $RE]
The above will also produce an empty element at the end of the pieces
list, because there's a terminating separator.
Upvotes: 1
Reputation: 4362
You could use this regex:
[^..]
That would match all characters that are not ..
.
Upvotes: 0
Reputation: 76
If there is p.e. no newline in the string you could get a list of your strings with:
set in a..b/c..de/f-g..xyz..abc..def..123..
set out [split [string map {.. \n} $in] \n]]
Upvotes: 6