STRING::REPLACE_RE 1g 2024-03-26 laplante@plcb.ca GOWEB/STRING — Replace Using Regular Expressions


title: “STRING::REPLACE_RE” version: “1.0.0” date: 2024-03-26 author: “laplante@plcb.ca” section: “1g” category: “GOWEB/STRING”


Name

string::replace_re Replace Using Regular Expressions

Synopsis

string::replace_re(string, new_string, re/.../)
replace_re(string, new_string, re/.../)
string::replaceRe(string, new_string, re/.../)
replaceRe(string, new_string, re/.../)

Description

The replace_re function replaces parts of a string with new_string based on a regular expression match.


Examples

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-

Author

laplante@plcb.ca

See Also


Version