On Thu, 22 Feb 2018, Sven Schreiber wrote:
the regsub function doc says:
"Arguments: s (string) match (string) repl (string)
Returns a copy of s in which all occurrences of the pattern match are
replaced using repl. The arguments match and repl are interpreted as
Perl-style regular expressions."
But 'repl' cannot be a regular expression, it has to be a literal string
which can be plugged in, right? Otherwise I don't see how it can work, or at
least I cannot get it to work...
'repl' does not have to be an "inert" string literal; it can be, for
example, an expression that refers to matches in @match. Example:
string test = "-100.35, A-Z, 1998-02-13"
string mod = regsub(test, "([0-9]+)-([0-9]+)-([0-9]+)", "\1\2\3")
? print mod
-100.35, A-Z, 19980213
Here dashes are removed selectively in a way that could not be done
with plain strsub.