A new string of the same type as input with all matches replaced by return values of fun. If no matches found returns the input itself.
import std.conv : to; string list = "#21 out of 46"; string newList = replaceFirst!(cap => to!string(to!int(cap.hit)+1)) (list, regex(`[0-9]+`)); assert(newList == "#22 out of 46");
This is a general replacement tool that construct a new string by replacing matches of pattern re in the input. Unlike the other overload there is no format string instead captures are passed to to a user-defined functor fun that returns a new string to use as replacement.
This version replaces the first match in input, see replaceAll to replace the all of the matches.