PERL to VB6 Regular Expressions

Posted on 2005-05-10
Last Modified: 2013-12-26
Hello all not sure if this should go here or the PERL channel...

I have a program I wrote in PERL some time ago and I am converting it to VB6.  One of the lines of code parses a large file using (among other criteria) the following regular expression:

if($Search =~ /^\w{3}\s{2}/) {

Basical it says if the first three characters of the variable $Strip are alphanumeric and the next two are whitespace... then do the indicated lines of code.  Is there a simple VB6 expression that would duplicate that or do I have to test each character individually?

Thank you
Question by:acaraciolo
    LVL 35

    Accepted Solution


    The regular expression pattern you're using is extremely similar to what it would be in VB:
     Dim RegEx As RegExp
     Set RegEx = New RegExp
     RegEx.Pattern = "^\w{3}\s{2}"
     If RegEx.Test(Strip) Then
      'your code
     End If

    But you could also just use the Like operator in VB, for example:
     If Strip Like "[A-Za-z0-9_][A-Za-z0-9_][A-Za-z0-9_]  *" Then
      'your code
     End If

    That would not be the exact same, as the \s in reg exp could also be form-feed, line-feed, carriage return, tab, or vertical tab as well as space.  If you could have one of those, then I'd say stick with the regexp


    Author Comment

    Whoops I may have spoke to soon.... when I tried your code in VB I get an error message 'user-define type not defined'  and when I looked in help it tells me RegExp is a jscript object.
    However the like character worked... would stilll like to use the first one seems like it would be much easier....  thanks again
    LVL 35

    Expert Comment

    I'm sorry, I forgot to tell you how to use it!

    You have to set a reference to Regular Expressions.  I only have VBA where I am right now, but in VBA it is listed as "Microsoft VBScript Regular Expressions", though it may be worded differently in VB.  I won't be home for another hour or so.  If you can't find what to reference, I can tell you when I get home and look at my VB6.

    Let me know either way, if I don't hear from you I'll assume you couldn't find it.  I'm also going to check in the meantime to see if there is a copy of vb6 around here I can check

    Author Comment

    Fantastic... It's Microsoft VBScript Regular Expressions 5.5 and it works great, thanks again!  I am a self taught programmer I learned PERL from the book PERL for Dummies and VB6 from a Learn VB6 manual I bought from ... so most of what I gain comes from the help of people on this site.  I should have checked the refrences first....I'll be able to use this extensively on this project.

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Join & Write a Comment

    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…
    This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
    Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
    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…

    728 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

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now