This should not be the accepted answer. _colon is undocumented and underscore-prefixed, it should not be used in production code. A better solution (considering that is okay to throw an exception if the format is incorrect) is:
I don’t know if it is among the possible cases, but in the case of input with spaces before and/or after ‘:’
istr=" 2 5 3 : 7 6 2 : 3: 9 12 2 :4 :11 23 1:2:11"
rs=findall(r"\d+ *: *\d+( *: *\d+)*",istr)
rngs=getindex.([istr],rs)
ints=replace(istr,(rngs.=>"")...)
parse.(Int,split(ints))
function parserange(rstr)
rng=parse.(Int,split(rstr,":"))
if length(rng)==2 insert!(rng,2,1) end
range(;zip([:start,:step,:stop],rng)...)
end
parserange.(rngs)
PS
I’d be curious to know alternative regular expressions to the one I found to locate the ranges and, if possible, some expressions to find the integers that are not arguments of the ranges (i.e. close -spaces apart- to ‘:’)