String to search.
Regular expression pattern.
Delegate
Regular expression attributes.
the resulting string.
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.
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.