Replaces the first match. In replacement, $1 / ${1} is a group's text, $name /
${name} a named group's, and $$ a dollar sign; a group that did not match (or does not
exist) gives "". $name takes the longest run of letters, digits and _, so write
${1}st rather than $1st.
Regex :: #import "Extensions/Regex";
re, _ := Regex.compile("(\\w+)@(\\w+)");
assert(Regex.replace(*re, "ada@home, bob@work", "$2:$1") == "home:ada, bob@work");
Regex.free_regex(*re);replace :: (re: *Regex, text: string, replacement: string) -> string
Parameters
- re: *Regex
- text: string
- replacement: string
Returns
- string
replace :: ($R: Type, text: string, replacement: string) -> string
Replaces the first match of the static pattern; replacement works as for a Regex.
Parameters
- $R: Type
- text: string
- replacement: string
Returns
- string
Regex :: #import "Extensions/Regex";
Digits :: Regex.Static("[0-9]+");
assert(Regex.replace(Digits, "1 2", "#") == "# 2");