replaceFirst

Construct a new string from input by replacing the first match with a string generated from it according to the format specifier.

To replace all matches use replaceAll.

  1. R replaceFirst(R input, RegEx re, const(C)[] format)
    R
    replaceFirst
    (
    R
    C
    RegEx
    )
    (,
    RegEx re
    ,
    const(C)[] format
    )
    if (
    is(C : dchar)
    &&
    isRegexFor!(RegEx, R)
    )
  2. R replaceFirst(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 with the first match (if any) replaced. If no match is found returns the input string itself.

Examples

assert(replaceFirst("noon", regex("n"), "[$&]") == "[n]oon");

Meta