RegEx: Am I missing something? 
Author Message
 RegEx: Am I missing something?

I was all e{*filter*}d and planning to use the new RegExp object in VBScript for
cleaning an address database among other things.  I just purchased Mastering
Regular Expressions  by Jeffrey E. F. Friedl and read most of it.  I found
this article on the web
http://www.*-*-*.com/
Then I tried to implement the following in VB6:

 Sub main()
    Dim regex As New RegExp
    Dim colMatch As MatchCollection
    regex.Pattern = "^\(?(\d{3})(-|\)?\s*)(\d{3})-?(\d{4})$"
    Set colMatch = regex.Execute("(800) 555-1212")
    MsgBox colMatch.Count
 End Sub

And I only get one (1).  Now, in Perl according to Mr. Friedl, I can use
this regular expression to extract the "800", the "555", and the "1212" but
colMatch.Count returns [1], meaning one match only.  Please tell me there is
a way to access the individual portions of the match such as backreferencing
allows within the match.  Please....

Thanks in advance.

-Mike Schinkel
President; VBxtras - The Ultimate Catalog and Source of Tools for Visual
Basic Developers Worldwide.
#123 on the 1999 Inc 500 List of the Fastest Growing Companies in America
http://www.*-*-*.com/



Fri, 13 Sep 2002 03:00:00 GMT  
 RegEx: Am I missing something?

This appears to be a bug in VB/VBScript's implementation of regular
expressions. It's not really remembering submatches enclosed in
parentheses as it should. The only workaround that I see for your
particular expression is to set the Global property to TRUE and to set
the Pattern property to "\d{3,4}". Of course such a weak pattern means
a lot of extra work filtering out bad expressions. <g>


: I was all e{*filter*}d and planning to use the new RegExp object in
VBScript for
: cleaning an address database among other things.  I just purchased
Mastering
: Regular Expressions  by Jeffrey E. F. Friedl and read most of it.  I
found
: this article on the web
:
http://www.*-*-*.com/
p.
: Then I tried to implement the following in VB6:
:
:  Sub main()
:     Dim regex As New RegExp
:     Dim colMatch As MatchCollection
:     regex.Pattern = "^\(?(\d{3})(-|\)?\s*)(\d{3})-?(\d{4})$"
:     Set colMatch = regex.Execute("(800) 555-1212")
:     MsgBox colMatch.Count
:  End Sub
:
: And I only get one (1).  Now, in Perl according to Mr. Friedl, I can
use
: this regular expression to extract the "800", the "555", and the
"1212" but
: colMatch.Count returns [1], meaning one match only.  Please tell me
there is
: a way to access the individual portions of the match such as
backreferencing
: allows within the match.  Please....
:
: Thanks in advance.
:
: -Mike Schinkel
: President; VBxtras - The Ultimate Catalog and Source of Tools for
Visual
: Basic Developers Worldwide.
: #123 on the 1999 Inc 500 List of the Fastest Growing Companies in
America
: http://www.*-*-*.com/

:
:
:



Sat, 14 Sep 2002 03:00:00 GMT  
 RegEx: Am I missing something?
They apparently implemented it in 5.5 (although it was
mistakingly included in the 5.1 documentation).

See under the heading "Submatches in VBScript" in article
http://msdn.microsoft.com/workshop/languages/clinic/scripting1213
99.asp

* Sent from RemarQ http://www.remarq.com The Internet's Discussion Network *
The fastest and easiest way to search and participate in Usenet - Free!



Sat, 14 Sep 2002 03:00:00 GMT  
 RegEx: Am I missing something?
Your RegExp isn't global. It stops after the first match. Add

  regex.Global = True

before you execute it. This is like the /g switch in Perl RexExps.

=-=-=
Steve
-=-=-


Quote:
> I was all e{*filter*}d and planning to use the new RegExp object in VBScript for
> cleaning an address database among other things.  I just purchased Mastering
> Regular Expressions  by Jeffrey E. F. Friedl and read most of it.  I found
> this article on the web
> http://www.*-*-*.com/
> Then I tried to implement the following in VB6:

>  Sub main()
>     Dim regex As New RegExp
>     Dim colMatch As MatchCollection
>     regex.Pattern = "^\(?(\d{3})(-|\)?\s*)(\d{3})-?(\d{4})$"
>     Set colMatch = regex.Execute("(800) 555-1212")
>     MsgBox colMatch.Count
>  End Sub

> And I only get one (1).  Now, in Perl according to Mr. Friedl, I can use
> this regular expression to extract the "800", the "555", and the "1212" but
> colMatch.Count returns [1], meaning one match only.  Please tell me there is
> a way to access the individual portions of the match such as backreferencing
> allows within the match.  Please....

> Thanks in advance.

> -Mike Schinkel
> President; VBxtras - The Ultimate Catalog and Source of Tools for Visual
> Basic Developers Worldwide.
> #123 on the 1999 Inc 500 List of the Fastest Growing Companies in America
> http://www.*-*-*.com/




Sat, 14 Sep 2002 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Am I missing something here ...? Instr Function

2. am I missing something ?

3. WSH 5.6 argument definitions - am I missing something?

4. Pop-up windows - Am I missing something?

5. Access Runtime - Am I Missing Something?

6. AM I missing something - Sum and Cumulative Sum

7. VBA For Dummies --- Am I missing something here?

8. Am I missing something?

9. Am I missing something?

10. Am I missing something incredibly easy?

11. Am I missing something in the DHTML Editor?

12. Undraggable controls: Am I Missing something???

 

 
Powered by phpBB® Forum Software