Syntax
RegExReplace <string> <regex> <replacement-text> [MatchCase]Description
Searches a string for matches to a specified regular expression and substitutes text generated according to a specified pattern for the instances found. A copy of the input string with the substitutions performed is returned.Parameters
<string>
- The string to search.
<regex>
- The regular expression to match (see the remarks section for details).
<replacement-text>
- The template for the substitution text (see the remarks section for details).
MatchCase
- Optional. if this parameter is present, matching is case sensitive.
Remarks
A regular expression string that contains "capture subexpressions" enclosed in parentheses. Each subexpression is assigned an index beginning with zero. The text matching the captured subexpressions can be included in the replacement text by prefixing the index with the $ character.The replacement text replaces the entire matching substring. The captured text may be placed in the replacement string by placing a $ character in the replacement string followed by a number. The number determines which matching substring is to be used. The matching substrings are numbered beginning with 0. (See the example below for a use of this feature.)
All matching instances of text in the string are replaced by a single execution of this statement.
The PatternSubstitute statement provides similar but less flexible functionality and uses a less complex pattern string than regular expressions.
Example
s = RegExReplace "http://www.p1.com/index.html." "(.*)://(.*)/(.*)" "Protocol=$1, Hostname=$2, file=$3"The above statement assigns the string "Protocol=http, Hostname=www.p1.com, file=index.html." to the variable s.