STRING::REPLACE_RE
1g 2024-03-26 laplante@plcb.ca GOWEB/STRING — Replace Using Regular Expressionstitle: “STRING::REPLACE_RE” version: “1.0.0” date: 2024-03-26 author: “laplante@plcb.ca” section: “1g” category: “GOWEB/STRING”
string::replace_re Replace Using Regular Expressions
string::replace_re(string, new_string, re/.../)
replace_re(string, new_string, re/.../)
string::replaceRe(string, new_string, re/.../)
replaceRe(string, new_string, re/.../)
The replace_re
function replaces parts of a string with new_string
based on a regular expression match.
new_string
parameter must immediately follow the string
parameter.$1
, ${1}
, or $name
.res={{
replace_re(re/a(x*)b/, "-ab-axxb-", "T"); "\n";
replace_re(re/a(x*)b/, "", ""); "\n";
replace_re(re/a(x*)b/, "-ab-axxb-", "$1"); "\n";
replace_re(re/a(x*)b/, "-ab-axxb-", "$1W"); "\n";
replace_re(re/a(x*)b/, "-ab-axxb-", "${1}W"); "\n"; "\n";
replace_re(re/a(?P<1W>x*)b/, "-ab-axxb-", "$1W"); "\n";
replace_re(re/a(?P<1W>x*)b/, "-ab-axxb-", "${1}W"); "\n";
}}.
Returns:
res=-T-T-
--xx-
---
-W-xxW-
--xx-
-W-xxW-
laplante@plcb.ca