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.
string baz(Captures!(string) m) { import std.string : toUpper; return toUpper(m.hit); } // Capitalize the letters 'a' and 'r': auto s = replaceAll!(baz)("Strap a rocket engine on a chicken.", regex("[ar]")); assert(s == "StRAp A Rocket engine on A chicken.");
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 all of the matches found in input, see replaceFirst to replace the first match only.