From: Phil Hibbs on
Aha, I fixed my problem, I was iterating over the Matches instead of
the Matches.SubMatches!

Phil.
From: Phil Hibbs on
Rick Rothstein wrote:
> If I understand what you are trying to do, you can do it without using
> regular expressions.

Sure, but I was replacing my current implementation with a regexp
version to see if it was more efficient. I thought that maybe a single
regexp call that returns the elements and their lengths would be more
efficient than separate trim, instr, mid, and length calls (or trim,
split, length calls in your suggeston). Turns out it isn't, partly
because I misunderstood the length thing. You don't get the lengths of
the sub-matches, just the length of the full expression match, so I
had to do the length call anyway, and the "rest of" can be very long
(up to 3MB).

Phil Hibbs.
From: Dana DeLouis on
On 4/20/2010 5:31 AM, Phil Hibbs wrote:
> Rick Rothstein wrote:
>> If I understand what you are trying to do, you can do it without using
>> regular expressions.
>
> Sure, but I was replacing my current implementation with a regexp
> version to see if it was more efficient. I thought that maybe a single
> regexp call that returns the elements and their lengths would be more
> efficient than separate trim, instr, mid, and length calls (or trim,
> split, length calls in your suggeston). Turns out it isn't, partly
> because I misunderstood the length thing. You don't get the lengths of
> the sub-matches, just the length of the full expression match, so I
> had to do the length call anyway, and the "rest of" can be very long
> (up to 3MB).
>
> Phil Hibbs.


Hi. Don't know if this is any faster...

Sub Demo()
Dim S As String
Dim v(1 To 2)
Dim P As Long

S = " This is a test "
S = Trim(S)
P = InStr(1, S, Space(1))
v(1) = Left$(S, P - 1)
v(2) = Mid$(S, P + 1)
End Sub

= = = = = = =
HTH :>)
Dana DeLouis
From: Phil Hibbs on
Ron Rosenfeld wrote:
> If I might suggest:
> "^\s*(\S+)\s(.*?)\s*$"

It wasn't the regular expression that was wrong, it's the way I was
using the return value. But that's probably a better regex than mine.

Phil Hibbs.
From: Phil Hibbs on
Dana DeLouis wrote:
> Hi.  Don't know if this is any faster...

That's almost exactly what my original code did. It has to process the
string three times (if you add a length call at the end), I was trying
to reduce the number of times.

Phil Hibbs.