replaceAll

Construct a new string from input by replacing all of the fragments that match a pattern re with a string generated from the match according to the format specifier.

To replace only the first match use replaceFirst.

  1. R replaceAll(R input, RegEx re, const(C)[] format)
    @trusted
    R
    replaceAll
    (
    R
    C
    RegEx
    )
    (,
    RegEx re
    ,
    const(C)[] format
    )
    if (
    is(C : dchar)
    &&
    isRegexFor!(RegEx, R)
    )
  2. R replaceAll(R input, RegEx re)

Parameters

input R

string to search

re RegEx

compiled regular expression to use

format const(C)[]

format string to generate replacements from, see the format string.

Return Value

Type: R

A string of the same type as input with the all of the matches (if any) replaced. If no match is found returns the input string itself.

Examples

// insert comma as thousands delimiter
auto re = regex(r"(?<=\d)(?=(\d\d\d)+\b)","g");
assert(replaceAll("12000 + 42100 = 54100", re, ",") == "12,000 + 42,100 = 54,100");

Meta