Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Regular Expressions & VB

Posted on 2000-03-31
5
304 Views
Last Modified: 2012-06-21
VBScript version 5 has a Regular Expression engine. Is there a way to access this functionality from within VB6?

How about a VBA-enabled app like Access2K?

thankx
--steve...

0
Comment
Question by:juststeve
  • 2
  • 2
5 Comments
 
LVL 6

Expert Comment

by:VBGuru
ID: 2673241
it should be possible if it is a com component
0
 
LVL 6

Expert Comment

by:VBGuru
ID: 2673244
it should be possible if it is a com component
0
 
LVL 4

Accepted Solution

by:
Nazdor earned 50 total points
ID: 2673422
Assuming you have VBscript installed, in VB, simply add a reference to:

    Micrsoft VBScript Regular Expressions

(Project -> References)

Use the object browser (F2) for help on the regular expressions (look for VBScript_RegExp)

The help isn't very clear - basically you need to create a RegExp variable, then use "Test" to see if it's there.  If you want to see what the match is, then use Execute with Match and MatchCollection - but normally you just need to find if it's in there.

    Dim re As New RegExp

    re.IgnoreCase = True
    re.Pattern = "This is a test"

    On Error Resume Next
    If re.Test("Test") = False Then
        Text1 = "Not Found"
    Else
        Text1 = "Found!"
    End If
    On Error Goto 0


The 'On Error' is there because re.Test *will* cause some nasty problems if your pattern matching is corrupted (or, rather, the limited pattern matching doesn't understand what you want).

I've not found a definitive list of available regexps, but it doesn't like a lot of what I would consider 'standard' regexps.

0
 
LVL 4

Expert Comment

by:Nazdor
ID: 2673433
ooops, "text1" refers to a textbox on the form - use msgbox or whatever instead...  same with .Pattern and "Test".  
0
 

Author Comment

by:juststeve
ID: 2673628
Not sure if I'm really going blind or not....prior to posting my question I'd added a reference to VBScript Global - but couldn't instantiate a RegExp object. Didn't see the VBScript Regular Expressions right underneath. Interestingly, both references point to the same filename (vbscript.dll) but the RegExp appends a \2 ??

You may wish to visit another question i have going right now titled Editing hyperlinks. I have a feeling the solution to that question is going to be RegExp-centered.

For the benefit of others viewing this question...excellent starter artical on RegExp at:
http://msdn.microsoft.com/library/periodic/period99/VB99I1.HTM
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

837 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question