[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

PERL to VB6 Regular Expressions

Posted on 2005-05-10
4
Medium Priority
?
400 Views
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
0
Comment
Question by:acaraciolo
  • 2
  • 2
4 Comments
 
LVL 35

Accepted Solution

by:
mvidas earned 2000 total points
ID: 13972393
acaraciolo,

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

Matt
0
 

Author Comment

by:acaraciolo
ID: 13972779
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
0
 
LVL 35

Expert Comment

by:mvidas
ID: 13972848
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
0
 

Author Comment

by:acaraciolo
ID: 13977148
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 www.kidware.com ... 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.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

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 …
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
Suggested Courses

834 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