Replaces the first limit matches (all of them when limit < 0).
- replacement: the new text;
$1or${1}stands for a group and$nameor${name}for a named one. - limit: how many matches to replace. Negative replaces all of them.
Regex :: #import "Extensions/Regex";
re, _ := Regex.compile("[0-9]+");
assert(Regex.replace_n(*re, "1 2 3", "#", 2) == "# # 3");
Regex.free_regex(*re);replace_n :: (
re: *Regex,
text: string,
replacement: string,
limit: int
) -> string
Replaces the first limit matches (all of them when limit < 0).
Parameters
- re: *Regex
- text: string
- replacement: string
- the new text;
$1or${1}stands for a group and$nameor${name}for a named one. - limit: int
- how many matches to replace. Negative replaces all of them.
Returns
- string
Regex :: #import "Extensions/Regex";
re, _ := Regex.compile("[0-9]+");
assert(Regex.replace_n(*re, "1 2 3", "#", 2) == "# # 3");
Regex.free_regex(*re);replace_n :: ($R: Type, text: string, replacement: string, limit: int) -> string
Replaces the first limit matches of the static pattern; negative replaces all.
Parameters
- $R: Type
- text: string
- replacement: string
- limit: int
Returns
- string
Regex :: #import "Extensions/Regex";
Digits :: Regex.Static("[0-9]+");
assert(Regex.replace_n(Digits, "1 2 3", "#", 2) == "# # 3");