View source code
Display the source code in std/regex.d from which this page was generated on
github.
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.
Page wiki
View or edit the community-maintained wiki page associated with this page.
Function std.regex.replaceAllInto
A variation on replaceAll
that instead of allocating a new string
on each call outputs the result piece-wise to the
. In particular
this enables efficient construction of a final output incrementally.
sink
As with replaceAll
there are 2 overloads - one with a format
string,
the other one with a user defined functor.
Prototypes
void replaceAllInto(Sink, R, C, RegEx)( Sink sink, R input, RegEx re, const(C)[] format ) @trusted if (isOutputRange!(Sink, dchar) && isSomeString!R && is(C : dchar) && isRegexFor!(RegEx, R)); void replaceAllInto(alias fun, Sink, R, RegEx)( Sink sink, R input, RegEx re ) @trusted if (isOutputRange!(Sink, dchar) && isSomeString!R && isRegexFor!(RegEx, R));
Example
//swap all 3 letter words and bring it back string text = "How are you doing?"; auto sink = appender!(char[])(); replaceAllInto!(cap => retro(cap[0]))(sink, text, regex(\b\w{3}\b
)); auto swapped = sink.data.dup; // make a copy explicitly assert(swapped == "woH era uoy doing?"); sink.clear(); replaceAllInto!(cap => retro(cap[0]))(sink, swapped, regex(\b\w{3}\b
)); assert(sink.data == text);
Authors
Dmitry Olshansky,
API and utility constructs are modeled after the original
by Walter Bright and Andrei Alexandrescu.
std.regex