util.Regexp.replaceAll

Substitutes all matches of the regular expression with the replacement string.

Syntax

util.Regexp.replaceAll(
  subject STRING,
  replacement STRING
 )
  RETURNS STRING
  1. subject is the string to be scanned.
  2. replacement is the replacement string.

Usage

The replaceAll() method scans the string passed as parameter, replaces each substring matching the current regular expression with the replacement string, and returns the new resulting string.

The replacement string can reference captured groups with the $num notation, where num is the ordinal position of the group delimited by parentheses in the regular expression, and where $0 represents the whole matching string.

Example

IMPORT util
MAIN
    DEFINE re util.Regexp
    LET re = util.Regexp.compile(`[@#%]([0-9]+)`)
    DISPLAY re.replaceAll("ABC#33 DE@891 FG#45","-$1")
END MAIN
Output:
ABC-33 DE-891 FG-45