xcall REGEX2, spattern, status, subject, flags, rpattern, outstr
REGEX2 supports a replacement operation, similar to that of MX_TRANSCOPY, except that it acts on a single string subject, pattern and replacement specification rather than a file-based set of them.
Parameters
spattern (String) [in]
search pattern, equivalent to pattern parameter in REGEX subroutine.
status, subject, flags
same as for REGEX
rpattern (String) [in]
replacement pattern, optionally including \# clauses referring to numbered capture sub-matches in the search pattern.
outstr (String) [out]
the string resulting from the replacement operation. If there were no matches (status < 1), then it will equal subject .
Note that as with MX_TRANSCOPY, the search and replace operation repeats until there are no more matches. For example, to replace all occurrences of "[#]" with "(#)" (where # is an integer of any size), you could use the following:
spattern = \[(\d+?)\] ! series of digits within [brackets]
rpattern = (\1) ! the matched digits, now with (parens)
This combination would replace "Funkhouser[13], Tavares[172], Griffin[9x]" with "Funkhouser(13), Tavares(172), Griffin[9x]". The third bracketed expression doesn't match the search pattern because of the "x".
History
2023 September, A-Shell 6.5.1743: Function added to A-Shell