REGEX_REPLACE
Use the REGEX_REPLACE script function to replace text in a string according to a regular expression and a replacement string.
Syntax
REGEX_REPLACE (String, Regex, Replacement String [, Flags])
Parameters
| Parameter | Description | Format | Allowed Values |
|---|---|---|---|
| String | Unicode character string to search | Script literal or script variable | n.a. |
| Regex | Regular expression to use. The regular expression uses the Boost C++ Libraries syntax. For more information, see the official Boost C++ Libraries documentation. | Script literal or script variable | n.a. |
| Replacement String | Replacement rule to use. For example, in regex group matching, $1, $2, and so on represent the matched groups 1, 2, and so forth, while $& signifies the complete match. For more information on marked sub-expressions, see the official Boost C++ Libraries documentation. | Script literal or script variable | n.a. |
| Flags
(Optional) |
Use flags to modify the operation. Flags can be combined and provided in any order — for example, combine i with n as "in" or "ni", or use the script variable &FLAG#. | Script literal or script variable |
|
Examples
Example 1
Getting an agent's version:
!* Input
:SET &AGENT# = "AR_MAIN_JWX6_VFRKARWIN01_01"
:SET &BUILD_VERSION# = SYS_INFO(AGENT, VERSION,, &AGENT#)
:PRINT Build version: &BUILD_VERSION#
!* Regex
:SET ®EX# = "\+.*"
:SET &REPLACE# = "\..*"
:SET ®EX_VERS# = "((\d+)\.\d+\.\d+).*"
:SET &RULE_VERS_MAIN# = "$2"
!* Get Agent's version and main version
:SET &VERS# = REGEX_REPLACE(&BUILD_VERSION#, ®EX_VERS#)
:SET &VERS_MAIN# = REGEX_REPLACE(&BUILD_VERSION#, ®EX_VERS_MAIN#)
:PRINT Agent '&AGENT#' is of version &VERS# and of main version &VERS_MAIN#
After the execution, the activation report (ACT) displays the following:
2025-08-04 18:08:08 - U00020408 Build version: 24.6.0+low.build.1754215201098
2025-08-04 18:08:08 - U00020408 Agent 'AR_MAIN_JWX6_VFRKARWIN01_01' is of version 24.6.0 and of main version 24
Example 2
Getting an agent's version using a replacement rule:
!* Input
:SET &AGENT# = "AR_MAIN_JWX6_VFRKARWIN01_01"
:SET &BUILD_VERSION# = SYS_INFO(AGENT, VERSION,, &AGENT#)
:PRINT Build version: &BUILD_VERSION#
!* Regex and replacement rule
:SET ®EX_VERS# = "((\d+)\.\d+\.\d+).*"
:SET &RULE_VERS# = "$1"
:SET &RULE_VERS_MAIN# = "$2"
!* Get Agent's version and main version using replacements rules
:SET &VERS# = REGEX_REPLACE(&BUILD_VERSION#, ®EX_VERS#, &RULE_VERS#)
:SET &VERS_MAIN# = REGEX_REPLACE(&BUILD_VERSION#, ®EX_VERS#, &RULE_VERS_MAIN#)
:PRINT Agent '&AGENT#' is of version &VERS# and of main version &VERS_MAIN#
After the execution, the activation report (ACT) displays the following:
2025-08-04 18:13:11 - U00020408 Build version: 24.6.0+low.build.1754215201098
2025-08-04 18:13:11 - U00020408 Agent 'AR_MAIN_JWX6_VFRKARWIN01_01' is of version 24.6.0 and of main version 24
Example 3
Getting an agent's version using a replacement rule and the u flag:
!* Input
:SET &AGENT# = "AR_MAIN_JWX6_VFRKARWIN01_01"
:SET &BUILD_VERSION# = SYS_INFO(AGENT, VERSION,, &AGENT#)
:PRINT Build version: &BUILD_VERSION#
!* Regex and replacement rule
:SET ®EX_VERS# = "((\d+)\.\d+\.\d+).*"
:SET &RULE_VERS# = "$1"
:SET &RULE_VERS_MAIN# = "$2"
!* Get Agent's version and main version using replacements rules and flag 'u'
:SET &VERS# = REGEX_REPLACE(&BUILD_VERSION#, ®EX_VERS#, &RULE_VERS#, 'u')
:SET &VERS_MAIN# = REGEX_REPLACE(&BUILD_VERSION#, ®EX_VERS#, &RULE_VERS_MAIN#, 'u')
:PRINT Agent '&AGENT#' is of version &VERS# and of main version &VERS_MAIN#
After the execution, the activation report (ACT) displays the following:
2025-08-04 18:16:04 - U00020408 Build version: 24.6.0+low.build.1754215201098
2025-08-04 18:16:04 - U00020408 Agent 'AR_MAIN_JWX6_VFRKARWIN01_01' is of version 24.6.0 and of main version 24
Example 4
! Extract start and end time of the job from the messenger output of the job report from a Windows job in Post Processing
:SET &HND# = PREP_PROCESS_REPORT ()
:PROCESS &HND#
: SET &REP_LINE# = GET_PROCESS_LINE(&HND#)
: SET &TIME_N_DATE# = REGEX_REPLACE(&REP_LINE#, "UCMDJP:.*(START AT |ENDED AT)(.*) .*", "$1: $2", "u")
: IF &TIME_N_DATE# <> ""
: PRINT &TIME_N_DATE#
: ENDIF
:ENDPROCESS
After running the Job, the post processing report (POST) displays the following:
2025-08-04 18:21:31 - U00020408 START AT : 04.08.2025/18:21:31
2025-08-04 18:21:31 - U00020408 ENDED AT : 04.08.2025/18:21:31
See also: