Results 1 to 18 of 18

Thread: [RESOLVED] [2005] RegEx Need Simple Ones

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jan 2001
    Location
    Florida
    Posts
    3,216

    Re: [2005] RegEx Need Simple Ones

    Quote Originally Posted by gigemboy
    The Regex man strikes back.... should handle all three cases...
    vb Code:
    1. Dim s As String = ""
    2. Dim Pattern As String = "^[\d]*$|^[a-zA-Z]*$|^[\s]{0}$"
    3. If System.Text.RegularExpressions.Regex.IsMatch(s, Pattern) = True Then
    4.       MessageBox.Show("Match!")
    5. Else
    6.       MessageBox.Show("No Match!")
    7. End If
    Hey thanks for that! It actually takes care of all my scenarios.
    Appreciate it!

  2. #2

    Thread Starter
    PowerPoster
    Join Date
    Jan 2001
    Location
    Florida
    Posts
    3,216

    Resolved [RESOLVED] [2005] RegEx Need Simple Ones

    I am NOT good with Regex expressions. I need 3 RegEx expressions.

    1. Is a value in a textbox empty?
    2. Is a value in a textbox a number?
    3. Is a value in a textbox only alpha characters?

    Thanks

  3. #3
    Registered User nmadd's Avatar
    Join Date
    Jun 2007
    Location
    U.S.A.
    Posts
    1,676

    Re: [2005] RegEx Need Simple Ones

    Hello,

    Do you really need to use RegEx? Couldn't you just do for the first two at least:

    vb.net Code:
    1. If Me.TextBox1.Text = String.Empty
    2.  
    3. If IsNumeric(Me.TextBox1.Text)

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Jan 2001
    Location
    Florida
    Posts
    3,216

    Re: [2005] RegEx Need Simple Ones

    Thanks but yes I DO need to use RegEx.

  5. #5
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: [2005] RegEx Need Simple Ones

    1. ^(.*)$
    2. ^([0-9]+)$
    3. ^([a-zA-Z]+)$

  6. #6

    Thread Starter
    PowerPoster
    Join Date
    Jan 2001
    Location
    Florida
    Posts
    3,216

    Re: [2005] RegEx Need Simple Ones

    1. ^(.*)$ Does not work
    2. ^([0-9]+)$ Works...thanks
    3. ^([a-zA-Z]+)$ Does not work

  7. #7
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: [2005] RegEx Need Simple Ones

    This one ?
    Code:
    Dim regx As Regex
            Dim regp As Match
            regx = New Regex("\s") 'Matches any whitespace character (including spaces, newlines, tabs, and so on)
            regp = regx.Match(TextBox1.Text)
            'Console.WriteLine("Emptystring" & regp.Length.ToString)
            regx = New Regex("[1-9]")
            regp = regx.Match(TextBox1.Text)
            'Console.WriteLine("Numbers" & regp.Length.ToString)
            regx = New Regex("[Aa-zZ]")
            regp = regx.Match(TextBox1.Text)
            'Console.WriteLine("Charaters" & regp.Length.ToString)
    Please mark you thread resolved using the Thread Tools as shown

  8. #8

    Thread Starter
    PowerPoster
    Join Date
    Jan 2001
    Location
    Florida
    Posts
    3,216

    Re: [2005] RegEx Need Simple Ones

    Quote Originally Posted by danasegarane
    This one ?
    Code:
    Dim regx As Regex
            Dim regp As Match
            regx = New Regex("\s") 'Matches any whitespace character (including spaces, newlines, tabs, and so on)
            regp = regx.Match(TextBox1.Text)
            'Console.WriteLine("Emptystring" & regp.Length.ToString)
            regx = New Regex("[1-9]")
            regp = regx.Match(TextBox1.Text)
            'Console.WriteLine("Numbers" & regp.Length.ToString)
            regx = New Regex("[Aa-zZ]")
            regp = regx.Match(TextBox1.Text)
            'Console.WriteLine("Charaters" & regp.Length.ToString)
    For the first one if I type " sdfsdf", I need it to come back false because there are other characters there.

  9. #9

    Thread Starter
    PowerPoster
    Join Date
    Jan 2001
    Location
    Florida
    Posts
    3,216

    Re: [2005] RegEx Need Simple Ones

    Quote Originally Posted by danasegarane
    This one ?
    Code:
    Dim regx As Regex
            Dim regp As Match
            regx = New Regex("\s") 'Matches any whitespace character (including spaces, newlines, tabs, and so on)
            regp = regx.Match(TextBox1.Text)
            'Console.WriteLine("Emptystring" & regp.Length.ToString)
            regx = New Regex("[1-9]")
            regp = regx.Match(TextBox1.Text)
            'Console.WriteLine("Numbers" & regp.Length.ToString)
            regx = New Regex("[Aa-zZ]")
            regp = regx.Match(TextBox1.Text)
            'Console.WriteLine("Charaters" & regp.Length.ToString)
    This one is wrong [1-9] cause if I type gghh123 it comes back True when it is obviously NOT a number.

  10. #10
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: [2005] RegEx Need Simple Ones

    Do you want to combine all these conditons ?
    Please mark you thread resolved using the Thread Tools as shown

  11. #11

    Thread Starter
    PowerPoster
    Join Date
    Jan 2001
    Location
    Florida
    Posts
    3,216

    Re: [2005] RegEx Need Simple Ones

    and this one is wrong [Aa-zZ] cause if I type gghh123 it comes back True when it is not all alpha characters.

  12. #12

    Thread Starter
    PowerPoster
    Join Date
    Jan 2001
    Location
    Florida
    Posts
    3,216

    Re: [2005] RegEx Need Simple Ones

    Quote Originally Posted by danasegarane
    Do you want to combine all these conditons ?
    Well, let's just get them to work separately first.

  13. #13
    Registered User nmadd's Avatar
    Join Date
    Jun 2007
    Location
    U.S.A.
    Posts
    1,676

    Re: [2005] RegEx Need Simple Ones

    Quote Originally Posted by jesus4u
    1. ^(.*)$ Does not work
    2. ^([0-9]+)$ Works...thanks
    3. ^([a-zA-Z]+)$ Does not work
    #3 seems to work for me.

  14. #14
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: [2005] RegEx Need Simple Ones

    Quote Originally Posted by jesus4u
    and this one is wrong [Aa-zZ] cause if I type gghh123 it comes back True when it is not all alpha characters.
    Post your code.

  15. #15

    Thread Starter
    PowerPoster
    Join Date
    Jan 2001
    Location
    Florida
    Posts
    3,216

    Re: [2005] RegEx Need Simple Ones

    Quote Originally Posted by nmadd
    #3 seems to work for me.
    My mistake #3 DOES work. Thanks

  16. #16

    Thread Starter
    PowerPoster
    Join Date
    Jan 2001
    Location
    Florida
    Posts
    3,216

    Re: [2005] RegEx Need Simple Ones

    Quote Originally Posted by penagate
    Post your code.
    Code:
    Sub Main()
    
    Dim s As String = "gghh123 "
    
    Dim regx As Regex
    Dim regp As Match
    
    regx = New Regex("[Aa-zZ]")
    regp = regx.Match(s)
    Look at the regp.Success property and you will see it is True.

  17. #17
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: [2005] RegEx Need Simple Ones

    Aa-zZ is not the same as a-zA-Z. The latter matches alphabetical characters regardless of case, by specifying two ranges; whereas I'm not entirely sure what the former matches—probably everything, or at least a large subset of the ASCII table.

    Note that you can also specify case-insensitivity using a flag, which is an optional parameter of the Regex constructor..

  18. #18
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: [2005] RegEx Need Simple Ones

    The Regex man strikes back.... should handle all three cases...
    vb Code:
    1. Dim s As String = ""
    2. Dim Pattern As String = "^[\d]*$|^[a-zA-Z]*$|^[\s]{0}$"
    3. If System.Text.RegularExpressions.Regex.IsMatch(s, Pattern) = True Then
    4.       MessageBox.Show("Match!")
    5. Else
    6.       MessageBox.Show("No Match!")
    7. End If

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width