?
Solved

Regular Expressions & VB

Posted on 2000-03-31
5
Medium Priority
?
308 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
[X]
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
  • 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 200 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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 process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

762 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