D Documentation  
sub
char[] sub(char[] string, char[] pattern, char[] format, char[] attributes = null)
char[] sub(char[] string, char[] pattern, char[] delegate(RegExp) dg, char[] attributes = null)

Searches string for matches with regular expression pattern with attributes and replaces those matches with a new string composed of format merged with the result of the matches.

If the multiple line attribute is set, ^ and $ represent the start and end of a line. If the multiple line attribute is not set, ^ and $ represent the start and end of the entire string.

If the global attribute is set, replace all matches. Otherwise, replace the first match.

Example:
import std.stdio;
import std.regexp;

int main() {
  // replace numbers with #
  char[] phone = "905-555-1234";
  phone = sub(phone,"[0-9]","#","g"); // global
  writefln("%s",phone);
  
  char[] str;
  // wrap all vowels with brackets
  str = sub("Hello","([aeiou])","[$1]","gi"); // global, ignore case
  writefln("%s",str);
  
  // $` is the stuff left of the match
  // $' is the stuff right of the match
  // $& is the match itself
  // remember $` is left because ` is on the left side of the keyobard
  str = sub("Hello","[aeiou]","($`$&$')","i"); // ignore case
  writefln("%s",str);
  
  return 0;
}

Output:
###-###-####
H[e]ll[o]
H(Hello)llo
Created using PHP docwiki written by Markus Dangl. Best viewed with Mozilla Firefox.