Solved

RegExp

Posted on 2003-12-07
11
767 Views
Last Modified: 2010-05-01
i don't quite understand this.. i can use it to set a pattern to parse certain things from a website? like.. if i want to get numbers and before each number is the exact same string.. i could set an RegExp pattern? ...i confused myself, someone wanna help?
0
Comment
Question by:learning_t0_pr0gram
  • 6
  • 5
11 Comments
 

Expert Comment

by:ROTRTechTeam
ID: 9894083
Regular Expressions is a COM object that, when used correctly, can do pattern matching on most anything you throw at it.  It is very powerful and allows you to limit the number of lines of code you use when doing comparisons (ie. attempting to determine if an email address entered into your application is in valid form, etc.)  It is mainly used for validation purposes, but there are many other uses.

What else can I tell you?
0
 
LVL 4

Author Comment

by:learning_t0_pr0gram
ID: 9896818
how about a simple example that might help me understand how to use it... i'd really like to know as much as i can about Visual Basic...
0
 

Accepted Solution

by:
ROTRTechTeam earned 30 total points
ID: 9897440
OK.  Here you go.  This function validates the form of an email address.  It makes certain that the address has a certain number of characters prior to the @ and that it has a certain number of characters after the @ and that it includes an @.  Basically, this will guarantee that the form of the email address is correct, but will not validate whether or not it is a real, active email address.

Function CheckEmailAddress(EmailAddress As String) As Boolean
    Dim bTemp As Boolean
    Dim objRE As RegExp
   
    Set objRE = New RegExp   <--- Create the object
   
    objRE.Pattern = "^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$"  <-- Set up the validation pattern
   
    If objRE.Test(EmailAddress) Then  <--- Check the address passed in against the validation pattern
        bTemp = True
    Else
        bTemp = False
    End If
   
    Set objRE = Nothing
   
    CheckEmailAddress = bTemp
End Function

That's about all there is to it.
0
 
LVL 4

Author Comment

by:learning_t0_pr0gram
ID: 9899186
^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$

^^Reaaaaaaaaalllly confuses me... i seen a site on it but the definitions they had for each symbol confused me...
0
 

Expert Comment

by:ROTRTechTeam
ID: 9899384
Let's break it down:

^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$

The ^ matches the beginning of the input.  It says "this is where to start"

\w matches any alphanumeric character, including the underscore

([\.-]?\w+)* means that a slash, period or dash is allowed as long as it is followed by any alphanumeric characters zero or more times (because of the *)

@ means there must be an @ symbol

\w matches any alphanumeric character, including the underscore

([\.-]?\w+)* means that a slash, period or dash is allowed as long as it is followed by any alphanumeric characters zero or more times (because of the *)


(\.\w{2,3})+$ allows for 2 to 3 characters after the final period (for the .com, .net, etc in the email address) with $ representing end of input.

Does that help?
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 4

Author Comment

by:learning_t0_pr0gram
ID: 9899507
hold on, i'm at school right now and its time to go, i'll be home in 5 minutes and i'll have a look at it...
0
 
LVL 4

Author Comment

by:learning_t0_pr0gram
ID: 9899645
what does the + do?
0
 

Expert Comment

by:ROTRTechTeam
ID: 9899785
The + just concatenates the expression together.  It basically combines the various patterns in the RegEx pattern.  If this was a sentence (my expression above) it would read:

Start at the beginning of the expression passed in.  Match any alphanumeric character and also allow slash, period and dash as long as it is followed by alphanumeric characters AND (+) include the @ symbol, continue by matching alphanumeric characters including the slash, period or dash, and make sure there is at least 1 period followed by at least two but no more than 3 characters.
0
 
LVL 4

Author Comment

by:learning_t0_pr0gram
ID: 9899835
ok, i kinda understand it now.. a couple more things though..

the ? and the *
0
 

Expert Comment

by:ROTRTechTeam
ID: 9904830
The ? means match zero or one time.
* means match zero or more times.
0
 
LVL 4

Author Comment

by:learning_t0_pr0gram
ID: 9915307
ok, it's understood a little better now..
i'll mess around with it a bit..

thx..



~Chris~
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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 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…

747 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

9 Experts available now in Live!

Get 1:1 Help Now