pcreReplace
pcreReplace(o_comPatObj t_source t_replacement x_index[x_options] ) =>t_result/t_source
Description
Replaces one or all occurrences of a previously-compiled regular expression in the given source string with the specified replacement string. The integer index indicates which of the matching substrings to replace. If the index is less than or equal to zero, the function applies the replacement string to all matching substrings. You can use an optional argument to specify independent option bits for controlling pattern matching. The matching algorithm is PCRE/Perl-compatible.
Arguments
|
Data object containing the compiled pattern returned from a previous |
|
|
Replacement string. You can use pattern tags in this string (see |
|
|
Integer index indicating which of the matching substrings to replace. If the index is less than or equal to zero, the function applies the replacement string to all matching substrings. |
|
|
(Optional) Independent option bits that affect pattern matching. Valid values for this argument are the same as those for the x_options argument to the |
Value Returned
|
Copy of the source string with the specified replacement (determined by the integer index). |
|
Examples
comPat1 = pcreCompile( "[0-9]+" )
=> pcreobj@0x27d258
pcreReplace( comPat1 "abc-123-xyz-890-wuv" "(*)" 0 )
=> "abc-(*)-xyz-(*)-wuv"
pcreReplace( comPat1 "abc-123-xyz-890-wuv" "(*)" 1 )
=> "abc-(*)-xyz-890-wuv"
pcreReplace( comPat1 "abc-123-xyz-890-wuv" "(*)" 2 )
=> "abc-123-xyz-(*)-wuv"
pcreReplace( comPat1 "abc-123-xyz-890-wuv" "(*)" 3 )
=> "abc-123-xyz-890-wuv"
comPat2 = pcreCompile( "xyz" ) => pcreobj@0x27d264
pcreReplace( comPat2 "xyzzyxyzz" "xy" 0 )
=> "xyzyxyz"
Related Topics
Return to top