Product Documentation
Cadence SKILL Language Reference
Product Version IC23.1, November 2023

rexReplace

rexReplace( 
t_source 
t_replacement 
x_index 
) 
=> t_result

Description

Returns a copy of the source string in which the specified substring instances that match the last compiled regular expression are replaced with the given string.

Scans the source string t_source to find all substring(s) that match the last regular expression compiled and replaces one or all of them by the replacement string t_replacement. The argument x_index tells which occurrence of the matched substring is to be replaced. If it’s 0 or negative, all the matched substrings will be replaced. Otherwise only the x_index occurrence is replaced. Returns the source string if the specified match is not found.

Arguments

t_source

Source string to be matched and replaced.

t_replacement

Replacement string to be used. Pattern tags can be used in this string (see rexSubstitute).

x_index

Specifies which of the matching substrings to replace. Do a global replace if it’s <= 0.

Value Returned

t_result

Copy of the source string with specified replacement or the original source string if no match was found.

Examples

rexCompile( "[0-9]+" )               
=> t
rexReplace( "abc-123-xyz-890-wuv" "(*)" 1)
=> "abc-(*)-xyz-890-wuv"
rexReplace( "abc-123-xyz-890-wuv" "(*)" 2)
=> "abc-123-xyz-(*)-wuv"
rexReplace( "abc-123-xyz-890-wuv" "(*)" 3)
=> "abc-123-xyz-890-wuv"
rexReplace( "abc-123-xyz-890-wuv" "(*)" 0)
=> "abc-(*)-xyz-(*)-wuv"
rexCompile( "xyz" )
=> t
rexReplace( "xyzzyxyzz" "xy" 0)
=> "xyzyxyz" ; no rescanning!
rexCompile("^teststr") 
rexReplace("teststr_a" "bb" 0)
=> "bb_a"
rexReplace("teststr_a" "bb&" 0) 
=> "b teststr_a"
rexReplace("teststr_a" "[&]" 0) 
=> "[teststr]_a"

Related Topics

String Functions

rexCompile

rexMatchp

rexSubstitute

rexExecute


Return to top
 ⠀
X