Solved

RegExp

Posted on 2003-12-07
11
772 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

910 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

19 Experts available now in Live!

Get 1:1 Help Now