Please enable JavaScript to view this site.

A-Shell Development History

xcall REGEX2, spattern, status, subject, flags, rpattern, outstr

New subroutine REGEX2.SBR 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  (Str)  [in]

search pattern, equivalent to pattern parameter in REGEX subroutine.

status, subject, flags

same as for REGEX

rpattern  (Str)  [in]

replacement pattern, optionally including \# clauses referring to numbered capture sub-matches in the search pattern.

outstr  (Str)  [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".