Rewriting the Replace Function
In VBScript, the Replace function replaces each occurrence of a given substring with new text. This function's syntax is
Replace(expression, find, _ replaceWith _
[, start[, count[, compare]]])
The function scans the text you specify in the expression argument and searches for all the occurrences of the substring you specify in the find argument. The function then replaces those substrings with the text you specify in the replaceWith argument, following the restrictions you set in the start, count, and compare arguments. (For more information about the Replace function's syntax, see my November 1999 column.) This function is a simple pattern-matching mechanism because it lets you identify and replace text that matches only one certain substring.
JScript's counterpart to the Replace function is the Replace method. This method's syntax is
stringObj.replace(rgExp, _ replaceText)
The method replaces the substrings that match the regular expression you specify in the rgExp argument with the text you specify in the replaceText argument. Because using a regular expression is a more powerful mechanism to identify text to replace than using a substring, JScript's Replace method is a more powerful search-and-replace tool than VBScript's Replace function. However, because VBScript now supports regular expressions, you can rewrite the Replace function so that it uses regular expressions to identify text to replace. This new user-defined function is called ReplaceEx. . . .