util.Regexp.replaceFirst
Substitutes the match of the regular expression with the replacement string.
Syntax
util.Regexp.replaceFirst(
subject STRING,
replacement STRING
)
RETURNS STRING
- subject is the string to be scanned.
- replacement is the replacement string.
Usage
The replaceFirst()
method scans the string passed as parameter, replaces the first
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.replaceFirst("ABC#33 DE@891 FG#45","-$1")
END MAIN
Output:
ABC-33 DE@891 FG#45