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() {
char[] phone = "905-555-1234";
phone = sub(phone,"[0-9]","#","g"); writefln("%s",phone);
char[] str;
str = sub("Hello","([aeiou])","[$1]","gi"); writefln("%s",str);
str = sub("Hello","[aeiou]","($`$&$')","i"); writefln("%s",str);
return 0;
}
|
Output:
###-###-####
H[e]ll[o]
H(Hello)llo |
|