VBScript » RegExp » Replace

Version: 5.0

Syntax:
object.Replace (String1, String2)
String1, String2
There are two mandatory arguments. If the search string pattern is found in one or more occurrences inside the string designated by the String1 argument, then, as set by the Global property, the first or all occurrences of the search string pattern will be replaced with the String2 argument.

This method is used to replace text found in a regular expression search. Do not confuse this method with the Replace function.

It can only be used with a RegExp object variable.

The search string pattern is declared using the Pattern property. You can use the Global property to limit the search to the first occurrence of a match, or all occurrences.

Examples

Code:
<%
Dim RegX
Set RegX = NEW RegExp
Dim MyString, SearchPattern, ReplacedText
MyString = "Ocelots make good pets."
SearchPattern = "good"
ReplaceString = "bad"
RegX.Pattern = SearchPattern
RegX.Global = True
ReplacedText = RegX.Replace(MyString, ReplaceString)
Response.Write(ReplacedText)
%>

Output:
"Ocelots make bad pets."