PERL to VB6 Regular Expressions

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
Who is Participating?
mvidasConnect With a Mentor Commented:

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

acaracioloAuthor Commented:
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
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
acaracioloAuthor Commented:
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.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.