www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Get "discarded" data from std.regex.splitter (or something else?)

reply "Steven Schveighoffer" <schveiguy yahoo.com> writes:
writeln(splitter("abc123def456", regex("[0-9]+", "g")));

outputs:

["abc", "def", ""]

But what if I want the "123" and "456" tokens too? Is there a way to do  
that?

-Steve
Jan 16 2014
parent Dmitry Olshansky <dmitry.olsh gmail.com> writes:
17-Jan-2014 00:52, Steven Schveighoffer пишет:
 writeln(splitter("abc123def456", regex("[0-9]+", "g")));

 outputs:

 ["abc", "def", ""]

 But what if I want the "123" and "456" tokens too? Is there a way to do
 that?
Well these 3 pieces are _slices_ of the original input, and with a bit of calculations on .ptr and .length you can figure out what's in between. Also you can just use matchAll which too, does return slices. It could be seen as dropping all in between matches ;)
 -Steve
-- Dmitry Olshansky
Jan 16 2014