Solved

Regular Expressions & VB

Posted on 2000-03-31
5
306 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 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Excel VBA, find a string in a column, update a cell 7 115
Spell Check in VB6 13 144
backup program with robocopy 6 87
VB6 calling COM DLL written in Visual Studio 2003 6 52
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

740 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