Joakim_
asked on
Regular Expression Replace with Many Patterns
Is it possible to use the replace function and define the pattern in the function, so I can have many patterns with only one object, just like in this C++ code: http://www.developer.com/net/cplus/article.php/3495511
If so, how?
If so, how?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That one replaces "T" with ">", which it shouldn't - I did it just for testing.
Usage of the function: just add as many "strResult = FormatTextRegExpReplace()" s as you want. Put the RegExp pattern in the first quotes, and what it should be replaced with in the second quotes.
In example...
strResult = FormatTextRegExpReplace(st rResult, "^;", " ")
...Replaces lines starting with ";" indented with three spaces.
Usage of the function: just add as many "strResult = FormatTextRegExpReplace()"
In example...
strResult = FormatTextRegExpReplace(st
...Replaces lines starting with ";" indented with three spaces.
ASKER
By the way, here's what I came up with - a handy function for using RegExp.Replace() function in the same way as Replace(), but this one with a RegExp pattern:
--------------------
Function FormatTextRegExpReplace(st
' Dimension variables.
Dim objFormatTextOrdinaryRegEx
' Create a regular expression object.
Set objFormatTextOrdinaryRegEx
' Set the regular expression pattern.
objFormatTextOrdinaryRegEx
' Match all occurrences of the pattern.
objFormatTextOrdinaryRegEx
' Set the function value.
FormatTextRegExpReplace = objFormatTextOrdinaryRegEx
' Reset server objects.
Set objFormatTextOrdinaryRegEx
End Function
Function FormatText(strString)
' Dimension variables.
Dim strResult ' Holds a randomly named variable. (I'll fix this comment later.)
strResult = FormatTextRegExpReplace(st
strResult = FormatTextRegExpReplace(st
strResult = FormatTextRegExpReplace(st
FormatText = strResult
End Function
Response.Write(FormatText(