Solved

RegExp

Posted on 2003-12-07
11
790 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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

Technology Partners: 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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
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…
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…

759 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