Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 809
  • Last Modified:

RegExp

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
learning_t0_pr0gram
Asked:
learning_t0_pr0gram
  • 6
  • 5
1 Solution
 
ROTRTechTeamCommented:
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
 
learning_t0_pr0gramAuthor Commented:
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
 
ROTRTechTeamCommented:
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
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!

 
learning_t0_pr0gramAuthor Commented:
^\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
 
ROTRTechTeamCommented:
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
 
learning_t0_pr0gramAuthor Commented:
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
 
learning_t0_pr0gramAuthor Commented:
what does the + do?
0
 
ROTRTechTeamCommented:
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
 
learning_t0_pr0gramAuthor Commented:
ok, i kinda understand it now.. a couple more things though..

the ? and the *
0
 
ROTRTechTeamCommented:
The ? means match zero or one time.
* means match zero or more times.
0
 
learning_t0_pr0gramAuthor Commented:
ok, it's understood a little better now..
i'll mess around with it a bit..

thx..



~Chris~
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 6
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now