The OpenD Programming Language

splitter

Splits a string r using a regular expression pat as a separator.

Splitter!(keepSeparators, Range, RegEx)
splitter
(
Flag!"keepSeparators" keepSeparators = No.keepSeparators
Range
RegEx
)
(
Range r
,
RegEx pat
)
if (
is(BasicElementOf!Range : dchar) &&
isRegexFor!(RegEx, Range)
)

Parameters

keepSeparators

flag to specify if the matches should be in the resulting range

r Range

the string to split

pat RegEx

the pattern to split on

Return Value

Type: Splitter!(keepSeparators, Range, RegEx)

A lazy range of strings

Examples

import std.algorithm.comparison : equal;
auto s1 = ", abc, de,  fg, hi, ";
assert(equal(splitter(s1, regex(", *")),
    ["", "abc", "de", "fg", "hi", ""]));

Split on a pattern, but keep the matches in the resulting range

import std.algorithm.comparison : equal;
import std.typecons : Yes;

auto pattern = regex(`([\.,])`);

assert("2003.04.05"
    .splitter!(Yes.keepSeparators)(pattern)
    .equal(["2003", ".", "04", ".", "05"]));

assert(",1,2,3"
    .splitter!(Yes.keepSeparators)(pattern)
    .equal([",", "1", ",", "2", ",", "3"]));

Meta