January 16, 2014 Get "discarded" data from std.regex.splitter (or something else?) | ||||
---|---|---|---|---|
| ||||
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 |
January 16, 2014 Re: Get "discarded" data from std.regex.splitter (or something else?) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | 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 |
Copyright © 1999-2021 by the D Language Foundation