On Saturday, 15 February 2020 at 22:30:03 UTC, Craig Dillabaugh wrote:
On Saturday, 15 February 2020 at 11:32:42 UTC, AlphaPurned wrote:
I've tried 10 different ways with split and splitter, I've used all the stuff that people have said online but nothing works. I always get a template mismatch error.

Why is something so easy to do so hard in D?

auto toks = std.regex.split(l, Regex("s"));
auto toks = std.regex.splitter(l, Regex("s"));
auto toks = std.regex.splitter(l, ctRegex!r"\.");

I had the same problem myself recently, and almost ended up here to ask the same question as you but stumbled across the following (ugly) solution without using regexs.

char[] line = "Split this by#space or#sign."

auto parts = line.splitter!(a => a=='#' | a==' ').array;

This works for me:

import std;
void main()
{
    string line = "Split this by#space or#sign.";
    auto parts = line.splitter(regex("[ #]")).array;
writeln(parts); // ["Split", "this", "by", "space", "or", "sign."]
}

Reply via email to