View source code
Display the source code in std/regex.d from which this
page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a
Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page.
Requires a signed-in GitHub account. This works well for small changes.
If you'd like to make larger changes you may want to consider using
local clone.
std.regex.Splitter/splitter
- multiple declarations
Function splitter
Splits a string r
using a regular expression pat
as a separator.
Parameters
Name | Description |
---|---|
keepSeparators | flag to specify if the matches should be in the resulting range |
r | the string to split |
pat | the pattern to split on |
Returns
A lazy range of strings
Example
import std .algorithm .comparison : equal;
auto s1 = ", abc, de, fg, hi, ";
assert(equal(splitter(s1, regex(", *")),
["", "abc", "de", "fg", "hi", ""]));
Example
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"]));
Struct Splitter
Splits a string r
using a regular expression pat
as a separator.
struct Splitter(Flag!("keepSeparators") keepSeparators = No .keepSeparators, Range, alias RegEx)
if (isSomeString!Range && isRegexFor!(RegEx, Range));
Properties
Name | Type | Description |
---|---|---|
empty [get]
|
bool | Forward range primitives. |
front [get]
|
Range | Forward range primitives. |
save [get]
|
auto | Forward range primitives. |
Methods
Name | Description |
---|---|
popFront
|
Forward range primitives. |
Parameters
Name | Description |
---|---|
keepSeparators | flag to specify if the matches should be in the resulting range |
r | the string to split |
pat | the pattern to split on |
Returns
A lazy range of strings
Example
import std .algorithm .comparison : equal;
auto s1 = ", abc, de, fg, hi, ";
assert(equal(splitter(s1, regex(", *")),
["", "abc", "de", "fg", "hi", ""]));
Example
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"]));
Authors
Dmitry Olshansky,
API and utility constructs are modeled after the original std
by Walter Bright and Andrei Alexandrescu.
License
Copyright © 1999-2018 by the D Language Foundation | Page generated by ddox.