D Documentation  
Regexp.replace
rchar[] replace(rchar[] string, rchar[] format)

Finds regular expression matches in string 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() {
  char[] contacts = 
     "Joe: joe@asdf.com\n"
    ~"Sarah: sarah@asdf.com\n"
    ~"Rob: rob@asdf.com";
  char[] simple_email_pattern = "([a-z]+@[a-z]+\\.[a-z]+)";
  char[] mailto = "<a href=\"mailto:$1\">$1</a>";
  
  // wrap all emails with mailto <a> tags
  RegExp reg = new RegExp(simple_email_pattern,"gi"); // global, ignore case
  char[] html = reg.replace(contacts,mailto);
  
  // wrap a <b> tag around the first word of every line
  reg.compile("^([a-z]+)","gmi"); // globlal, multiline, ignore case
  html = reg.replace(html,"<b>$1</b>");
  
  // make every line a paragraph
  reg.compile("^(.+)$","gm"); // global, multiline
  html = reg.replace(html,"<p>$1</p>\n");
  
  writefln("%s",html);
  return 0;
}

Output:
<p><b>Joe</b>: <a href="mailto:joe@asdf.com">joe@asdf.com</a></p>
<p><b>Sarah</b>: <a href="mailto:sarah@asdf.com">sarah@asdf.com</a></p>
<p><b>Rob</b>: <a href="mailto:rob@asdf.com">rob@asdf.com</a>
Created using PHP docwiki written by Markus Dangl. Best viewed with Mozilla Firefox.