Replace Method
Replace the text found in the regular expression search.
Object. Replace (String1, string2)
Parameters
Object
Required. Always oneRegexpObject Name.
String1
Required.String1Is the string to be replaced by text.
String2
Required.String2Is to replace the text string.
Description
The actual mode of the replaced text is throughRegexpObjectPatternAttribute.
ReplaceMethod returnString1InRegexp. PatternThe text has been replacedString2. If no matching text is found, the originalString1.
The example below illustratesReplaceMethod usage.
Function replacetest (patrn, replstr) dim RegEx, str1'
Create a variable.Str1 = "The quick brown fox jumped over the lazy dog ."
Set RegEx = new Regexp'
Create a regular expression.RegEx. pattern = patrn'
Set the mode.RegEx. ignorecase = true'
Set whether to be case sensitive.Replacetest =RegEx. Replace (Str1,Replstr)
'
.End Function
Msgbox (replacetest ("Fox", "cat "))'
Set'Fox'
Replace'Cat'
.
In addition,ReplaceMethod to replace subexpressions in the mode. Next, replace all the word pairs in the original string with the calls to functions in the previous example:
Msgbox (replacetext ("(\ s +)", "$3 $2 $1 "))'
Exchange word pairs.