sub

Search string for matches with regular expression pattern with attributes. Pass each match to delegate dg. Replace each match with the return value from dg.

  1. string sub(string s, string pattern, string format, string attributes)
  2. string sub(string s, string pattern, string delegate(RegExp) dg, string attributes)
    string
    sub
    (
    string s
    ,
    string pattern
    ,
    string delegate dg
    ,
    string attributes = null
    )

Parameters

s string

String to search.

pattern string

Regular expression pattern.

dg string delegate

Delegate

attributes string

Regular expression attributes.

Return Value

Type: string

the resulting string.

Examples

Capitalize the letters 'a' and 'r':

s = "Strap a rocket engine on a chicken.";
sub(s, "[ar]",
   delegate char[] (RegExp m)
   {
        return toUpper(m[0]);
   },
   "g");    // result: StRAp A Rocket engine on A chicken.

Meta