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.
Function std.regex.replaceFirstInto
A variation on replaceFirst
that instead of allocating a new string
on each call outputs the result piece-wise to the sink
. In particular
this enables efficient construction of a final output incrementally.
void replaceFirstInto(Sink, R, C, RegEx)
(
ref Sink sink,
R input,
RegEx re,
const(C)[] format
) @trusted
if (isOutputRange!(Sink, dchar) && isSomeString!R && is(C : dchar) && isRegexFor!(RegEx, R));
void replaceFirstInto(alias fun, Sink, R, RegEx)
(
Sink sink,
R input,
RegEx re
) @trusted
if (isOutputRange!(Sink, dchar) && isSomeString!R && isRegexFor!(RegEx, R));
Like in replaceFirst
family of functions there is an overload
for the substitution guided by the format
string
and the one with the user defined callback.
Example
import std .array;
string m1 = "first message\n";
string m2 = "second message\n";
auto result = appender!string();
replaceFirstInto(result, m1, regex(`([a-z]+) message`), "");
//equivalent of the above with user-defined callback
replaceFirstInto!(cap=>cap[1])(result, m2, regex(`([a-z]+) message`));
writeln(result .data); // "first\nsecond\n"
Authors
Dmitry Olshansky,
API and utility constructs are modeled after the original std
by Walter Bright and Andrei Alexandrescu.
License
Copyright © 1999-2024 by the D Language Foundation | Page generated by ddox.