I would like to write some D code that would take a string, and split it by " "
, but not "\ "
. I normally use std.array.split
for splitting, but it obviously can't handle this. What would be the best way to do what I want?
Regular expressions (+ lookbehind) is powerful enough for that:
import std.regex;
void main()
{
auto parts = split(r"foo bar\ bar baz", regex(r"(?<!\\) "));
assert(parts == ["foo", r"bar\ bar", "baz"]);
}