R
Ron Rosenfeld
So do you think there's a difference between:
Dim re as Object
Set re = CreateObject("vbscript.regexp")
... and ...
Dim re as RegExp
Set re = New RegExp
?
I'll test it but I wondered if you have some insight into this. The
rest of my code (the actual regexp pattern test) is the same as yours.
Thanks!
No, there should not be any difference so long as you have a reference set to
Microsoft VBScript Regular Expressions 5.5. (That is not required with my
code). Also, if you have the reference set, I would DIM mc as match collection
rather than as object.
For trouble shooting, I would suggest you first try my code exactly as written,
all by itself (i.e. not embedded within your code).
In other words, enter the code I posted all by itself in a module.
Then --
A1: (please copy/paste from here)
<p id="height10" class="price-strike2">$2,599.00/EA Each</p>
B1:
=GetStrike2($A$1)
And see if that works. (returns $2,599.00)
If that works, and you want to use early-binding, set the Reference and use
this code instead:
====================================
Option Explicit
Function GetStrike2(sStr As String)
Dim re As RegExp, mc As MatchCollection
Set re = New RegExp
re.IgnoreCase = True
re.Pattern = """price-strike2"">(\$[0-9]*,?[0-9]*\.?[0-9]*)"
If re.test(sStr) = True Then
Set mc = re.Execute(sStr)
GetStrike2 = mc(0).submatches(0)
End If
Set re = Nothing
End Function
===============================
Again, use it "stand-alone"
If both work, then your problem is elsewhere.
--ron