The OpenD Programming Language

replaceAll

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.

  1. R replaceAll(R input, RegEx re, const(C)[] format)
  2. R replaceAll(R input, RegEx re)
    @trusted
    R
    replaceAll
    (
    alias fun
    R
    RegEx
    )
    (,
    RegEx re
    )
    if (
    isRegexFor!(RegEx, R)
    )

Parameters

input R

string to search

re RegEx

compiled regular expression

fun

delegate to use

Return Value

Type: R

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.

Examples

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.");

Meta