Regular expressions and/or pattern matching in VBA? 
Author Message
 Regular expressions and/or pattern matching in VBA?

Hi,

I know that there is an InStr function that allows character pattern
matching.

However, is there something that somebody has written that is more
'perl-regular-expression'-like? Something that allows you to take one
pattern and one string and tells you whether or not the pattern matches the
string? Also, it would be nice to have range ([a-z0-9]) operators repetition
operators (*,+) and memorization operators (\1, \2, etc.)

The best thing I've found is something on MSFT's website, but even then, the
best pattern matcher only matches same length strings to each other without
the * or + operators.

Thanks in advance for your help.

Please send mail to me in addition to the newsgroup.



Mon, 11 Nov 2002 03:00:00 GMT  
 Regular expressions and/or pattern matching in VBA?
Have you looked at the "Like" operator?  It doesn't have everything you
want, but it's more comprehensive than InStr().

--

Dirk Goldgar
(remove NOSPAM from reply address)



Quote:
> Hi,

> I know that there is an InStr function that allows character pattern
> matching.

> However, is there something that somebody has written that is more
> 'perl-regular-expression'-like? Something that allows you to take one
> pattern and one string and tells you whether or not the pattern matches
the
> string? Also, it would be nice to have range ([a-z0-9]) operators
repetition
> operators (*,+) and memorization operators (\1, \2, etc.)

> The best thing I've found is something on MSFT's website, but even then,
the
> best pattern matcher only matches same length strings to each other
without
> the * or + operators.

> Thanks in advance for your help.

> Please send mail to me in addition to the newsgroup.



Mon, 11 Nov 2002 03:00:00 GMT  
 Regular expressions and/or pattern matching in VBA?
Sure, I've tried that, but it doesn't meet my needs (which you did
recognize) because it doesn't extract the matching portion of the string...

For example, I want match_function("string_one (<letter><number>)
string_two", "\w\d") to become <letter><number> where we don't know which
letter or which number will go in, just that there's a letter and a number
there.

If I am wrong, please reply. Thanks.

Quote:

>Have you looked at the "Like" operator?  It doesn't have everything you
>want, but it's more comprehensive than InStr().

>--

>Dirk Goldgar
>(remove NOSPAM from reply address)






Mon, 11 Nov 2002 03:00:00 GMT  
 Regular expressions and/or pattern matching in VBA?
I see.  I didn't realize you wanted to extract the matched portion of the
string.  No, sorry, I don't know of an existing function to do that.

--

Dirk Goldgar
(remove NOSPAM from reply address)



Quote:
> Sure, I've tried that, but it doesn't meet my needs (which you did
> recognize) because it doesn't extract the matching portion of the
string...

> For example, I want match_function("string_one (<letter><number>)
> string_two", "\w\d") to become <letter><number> where we don't know which
> letter or which number will go in, just that there's a letter and a number
> there.

> If I am wrong, please reply. Thanks.


> >Have you looked at the "Like" operator?  It doesn't have everything you
> >want, but it's more comprehensive than InStr().

> >--

> >Dirk Goldgar
> >(remove NOSPAM from reply address)






Mon, 11 Nov 2002 03:00:00 GMT  
 Regular expressions and/or pattern matching in VBA?
If you install the 5.1 build of MS Scripting Engine, you *might* be able to
use the new RegExp functionality in VBS.
 http://msdn.microsoft.com/scripting/ )

Caveat: I haven't tried it from VBA myself.

 -- Dev

:Hi,
:
:I know that there is an InStr function that allows character pattern
:matching.
:
:However, is there something that somebody has written that is more
:'perl-regular-expression'-like? Something that allows you to take one
:pattern and one string and tells you whether or not the pattern matches the
:string? Also, it would be nice to have range ([a-z0-9]) operators
repetition
:operators (*,+) and memorization operators (\1, \2, etc.)
:
:The best thing I've found is something on MSFT's website, but even then,
the
:best pattern matcher only matches same length strings to each other without
:the * or + operators.
:
:Thanks in advance for your help.
:
:Please send mail to me in addition to the newsgroup.
:
:



Tue, 12 Nov 2002 03:00:00 GMT  
 Regular expressions and/or pattern matching in VBA?
Dev,

Kind of a subtle way of following up on that rumor you mentioned
a while back. ;-)

I assume that you're referring to these sentences in that
article:

   "The stdin/stdout/stderr support is actually
    implemented in the FileSystemObject, so
    you can now access stdin/stdout/stderr
    from any Visual Basic program.   . . .
    As an added bonus, you also get a regular
    expression object with VBScript 5.0 that
    can be used in Visual Basic."

I can hardly believe that it can be as simple as:

    "Just install Beta 2 of WSH 2.0 and you're set."

What then?  Read all the white papers, add a reference, check the
Object Browser, and just use the methods?  In Access 97?  Even
without the SRs?  I suppose that in theory it could work, but I'm
a little sceptical.  What the heck, I'm going to set up two or
three more machines over the next few weeks, maybe I'll get a
chance to give it a try on one that doesn't care if it gets bent
out of shape.

If anyone finds out more about this, please post an Info: RegExp

Marsh

Quote:

>If you install the 5.1 build of MS Scripting Engine, you *might*
be able to
>use the new RegExp functionality in VBS.
> http://msdn.microsoft.com/scripting/ )

>Caveat: I haven't tried it from VBA myself.

> -- Dev

-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----==  Over 80,000 Newsgroups - 16 Different Servers! =-----


Thu, 14 Nov 2002 03:00:00 GMT  
 Regular expressions and/or pattern matching in VBA?

--
Dev Ashish     (http://www.mvps.org/access)


: Dev,
:
: Kind of a subtle way of following up on that rumor you mentioned
: a while back. ;-)

:-)

:
: I assume that you're referring to these sentences in that
: article:

Not quite, because we don't have to use FSO.

:
: I can hardly believe that it can be as simple as:
:
:     "Just install Beta 2 of WSH 2.0 and you're set."

Should be just as simple as that. On my Windows 2000 RC-2 machine, it
requires just one additional ref. to "Microsoft VBScript Regular
Expressions".  Here's a quick test to prove the theory.

' ****** Code Start *******
Sub sTestZipCodes()
Const ERR_ZIPCODE = "Must be a valid 5 or 9 digit zip code"
    Debug.Print fValidateZipcode("06905")
    Debug.Print fValidateZipcode("06905-0011")
    Debug.Print fValidateZipcode("zxf44")
    Debug.Print fValidateZipcode("000922")
End Sub

Function fValidateZipcode(strZipCode As String) As Boolean
On Error GoTo ErrHandler
' Windows 2000: Requires a reference to VBScript Regular Expressions
' VBScript_RegExp - C:\WINNT\System32\vbscript.dll\2; 1.0
Dim objRE As VBScript_RegExp.RegExp

    Set objRE = New VBScript_RegExp.RegExp
    With objRE
        .Pattern = "^\d{5}([ -]?\d{4})?$"
        fValidateZipcode = (.Test(strZipCode))
    End With
    Set objRE = Nothing
ExitHere:
    Exit Function
ErrHandler:
    fValidateZipcode = False
    With Err
        MsgBox "Error: " & .Number & vbCrLf & .Description, _
            vbCritical Or vbOKOnly, .Source
    End With
    Resume ExitHere
End Function
' ********* Code End ********

  -- Dev



Thu, 14 Nov 2002 03:00:00 GMT  
 Regular expressions and/or pattern matching in VBA?
Dev,

Sure glad to see you back here, even if it's only some of the
time.

Didn't mean for you to actually go and do it, but if it's that
simple, it probably wasn't much of a strain on your Sunday
morning schedule ;-)

This can open up some intriguing possiblities.  Now I'll have to
think of a way to train users in the benefits of REs in their
search forms ;-)))  (Note to myself: check on the relative
performance.)

I appreciate the quick comeback along with the proof.
Marsh

Quote:
>Dev Ashish     (http://www.mvps.org/access)



>: Dev,
>:
>: Kind of a subtle way of following up on that rumor you
mentioned
>: a while back. ;-)

>:-)

>:
>: I assume that you're referring to these sentences in that
>: article:

>Not quite, because we don't have to use FSO.

>:
>: I can hardly believe that it can be as simple as:
>:
>:     "Just install Beta 2 of WSH 2.0 and you're set."

>Should be just as simple as that. On my Windows 2000 RC-2
machine, it
>requires just one additional ref. to "Microsoft VBScript Regular
>Expressions".  Here's a quick test to prove the theory.

>' ****** Code Start *******
>Sub sTestZipCodes()
>Const ERR_ZIPCODE = "Must be a valid 5 or 9 digit zip code"
>    Debug.Print fValidateZipcode("06905")
>    Debug.Print fValidateZipcode("06905-0011")
>    Debug.Print fValidateZipcode("zxf44")
>    Debug.Print fValidateZipcode("000922")
>End Sub

>Function fValidateZipcode(strZipCode As String) As Boolean
>On Error GoTo ErrHandler
>' Windows 2000: Requires a reference to VBScript Regular
Expressions
>' VBScript_RegExp - C:\WINNT\System32\vbscript.dll\2; 1.0
>Dim objRE As VBScript_RegExp.RegExp

>    Set objRE = New VBScript_RegExp.RegExp
>    With objRE
>        .Pattern = "^\d{5}([ -]?\d{4})?$"
>        fValidateZipcode = (.Test(strZipCode))
>    End With
>    Set objRE = Nothing
>ExitHere:
>    Exit Function
>ErrHandler:
>    fValidateZipcode = False
>    With Err
>        MsgBox "Error: " & .Number & vbCrLf & .Description, _
>            vbCritical Or vbOKOnly, .Source
>    End With
>    Resume ExitHere
>End Function
>' ********* Code End ********

>  -- Dev

-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----==  Over 80,000 Newsgroups - 16 Different Servers! =-----


Thu, 14 Nov 2002 03:00:00 GMT  
 Regular expressions and/or pattern matching in VBA?
Does anyone know how to get a Reference to VBSCRIPT.DLL\2 in VBA under
Access 97? It works fine in Access 2000, but the RegExp does not show
up in the list of available references under Access 97.
I found a page on the MS scripting site that has as title:

VBScript Features not in Visual Basic for Applications

http://msdn.microsoft.com/scripting/default.htm?/scripting/VBScript/doc/
vsgrpVBSFeatures.htm

RegExp is listed on this page, but there is no further explanation as
to why...

Does anyone have a clue?

Regards, Tim

Sent via Deja.com http://www.deja.com/
Before you buy.



Sun, 17 Nov 2002 03:00:00 GMT  
 
 [ 9 post ] 

 Relevant Pages 

1. Regular Expressions to Match a Pattern

2. Regular Expressions Repace Pattern

3. needed: regular expression pattern

4. regular expression pattern

5. Regular Expression Pattern with Smart Quotes

6. Repetitive pattern devided by space in regular expression

7. HELP - adv. regular expression - pattern

8. This regular expression pattern should be easy

9. Regular Expression, ORing the patterns.

10. Regular Expression -Pattern Operator

11. Regular expression pattern

12. needed: regular expression pattern...

 

 
Powered by phpBB® Forum Software