Regex Capture problem
On Wed, 25 Apr 2007 08:56:04 -0700, Dave Runyan
wrote:
I am using the VBScript_RegExp_55 library in an Excel-based VBA project to
build a text-file processor that uses rules stored in an Excel spreadsheet.
I have used Regex utilities before, so I understand the concepts of text
capture and re-use in a Regex expression.
But when I try to capture text with (*), for example, and then try to re-use
it with \1, I get either no changes made, or an object-generated error 5081.
I have not been able to isolate when these two results occur.
I believe my program code is basically correct, because I can do search and
replace type stuff just fine, including in the same "run" as the capture
operations that fail. Here are my options settings:
objRgx.IgnoreCase = False ' Set case sensitive.
objRgx.Global = True ' Set replace all.
objRgx.MultiLine = True ' Set multiline mode.
Thanks for any help you can provide.
Unfortunately, I'm still not following your example.
But, so far as your question about capturing text with (*), and then re-using
it, note the following:
Given the UDF:
===================================
Function RESub(str As String, SrchFor As String, ReplWith As String) As String
Dim objRegExp As RegExp
Set objRegExp = New RegExp
objRegExp.Pattern = SrchFor
objRegExp.IgnoreCase = True
objRegExp.Global = True
objRegExp.MultiLine = True
RESub = objRegExp.Replace(str, ReplWith)
End Function
================================
With these simple parameters:
str = "Now is the time"
SrchFor = Now is (.*) time
ReplWith = "$1"
Function returns "the" as would be expected.
--ron
|