Features
Ask DevGuru
ASP Resources
Find the Bug
Knowledge Base
Links
Tips of the Week
Tutorials
Products
dgCalendar
dgCharge New!
dgChart New!
dgFileUpload
dgReport New!
dgSort
dgTree
Site
Authoring
Coming Soon
DevGuru Resume
Link to Us
Merchandise
Sponsorships
Testimonials
What's New
Technologies
ADO 2.6
ASP
CSS2
HTML
JavaScript
Jet SQL
Transact-SQL Syntax
VBScript
WML
WMLScript
WSH
XML DOM
All Methods
Match Object
Matches Collection
METHOD: object.Replace
Implemented in version 5.0
object.
Replace
(String1, String2)
The
Replace
method is used to replace text in a regular expression search. It can only be used with a
RegExp
object variable.
Do not confuse this method with the
Replace
function.
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.
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.
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."
Copyright 1999-2001 by Infinite Software Solutions, Inc. All rights reserved.
Trademark Information