Solved

RegExp

Posted on 2003-12-07
11
795 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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
 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
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 …
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…
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…
Suggested Courses
Course of the Month5 days, 20 hours left to enroll

627 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