Re: Regex Capture problem



Thanks, Ron - as it is so often the problem was the nut holding the wheel. I
"learned" my regex using a freeware utility that had slightly different
syntax, so I had to convert many lines of expressions. Along the way I
somehow forgot that * is an enumerator, not a character placeholder - so I
was trying to capture (*) instead of (.*). As soon as I saw your fragment I
realized what the problem was.

Initially I ALSO had the parameters backwards in the method invocation
(having the search in a proprerty, and the input and replacement strings in
the call is just hard for me to grok it seems), but when I fixed that, I then
made the * error and the message I got was the same, 5018, with no helpful
text.

Okay - thanks again for your help - I will probably be asking something
again sooner than I imagine.

"Ron Rosenfeld" wrote:

On Wed, 25 Apr 2007 08:56:04 -0700, Dave Runyan
<DaveRunyan@xxxxxxxxxxxxxxxxxxxxxxxxx> 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 spread***.
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

.