|
-
Dec 25th, 2006, 03:41 PM
#1
Thread Starter
PowerPoster
Re: [2005] RegEx Need Simple Ones
 Originally Posted by gigemboy
The Regex man strikes back.... should handle all three cases...
vb Code:
Dim s As String = ""
Dim Pattern As String = "^[\d]*$|^[a-zA-Z]*$|^[\s]{0}$"
If System.Text.RegularExpressions.Regex.IsMatch(s, Pattern) = True Then
MessageBox.Show("Match!")
Else
MessageBox.Show("No Match!")
End If
Hey thanks for that! It actually takes care of all my scenarios.
Appreciate it!
-
Jul 2nd, 2007, 08:58 AM
#2
Thread Starter
PowerPoster
[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
-
Jul 2nd, 2007, 09:04 AM
#3
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:
If Me.TextBox1.Text = String.Empty
If IsNumeric(Me.TextBox1.Text)
-
Jul 2nd, 2007, 09:05 AM
#4
Thread Starter
PowerPoster
Re: [2005] RegEx Need Simple Ones
Thanks but yes I DO need to use RegEx.
-
Jul 2nd, 2007, 09:05 AM
#5
Re: [2005] RegEx Need Simple Ones
1. ^(.*)$
2. ^([0-9]+)$
3. ^([a-zA-Z]+)$
-
Jul 2nd, 2007, 09:11 AM
#6
Thread Starter
PowerPoster
Re: [2005] RegEx Need Simple Ones
1. ^(.*)$ Does not work
2. ^([0-9]+)$ Works...thanks
3. ^([a-zA-Z]+)$ Does not work
-
Jul 2nd, 2007, 09:13 AM
#7
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
-
Jul 2nd, 2007, 09:21 AM
#8
Thread Starter
PowerPoster
Re: [2005] RegEx Need Simple Ones
 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.
-
Jul 2nd, 2007, 09:23 AM
#9
Thread Starter
PowerPoster
Re: [2005] RegEx Need Simple Ones
 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.
-
Jul 2nd, 2007, 09:24 AM
#10
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
-
Jul 2nd, 2007, 09:25 AM
#11
Thread Starter
PowerPoster
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.
-
Jul 2nd, 2007, 09:25 AM
#12
Thread Starter
PowerPoster
Re: [2005] RegEx Need Simple Ones
 Originally Posted by danasegarane
Do you want to combine all these conditons ?
Well, let's just get them to work separately first.
-
Jul 2nd, 2007, 09:40 AM
#13
Re: [2005] RegEx Need Simple Ones
 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.
-
Jul 2nd, 2007, 09:42 AM
#14
Re: [2005] RegEx Need Simple Ones
 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.
-
Jul 2nd, 2007, 09:43 AM
#15
Thread Starter
PowerPoster
Re: [2005] RegEx Need Simple Ones
 Originally Posted by nmadd
#3 seems to work for me.
My mistake #3 DOES work. Thanks
-
Jul 2nd, 2007, 09:46 AM
#16
Thread Starter
PowerPoster
Re: [2005] RegEx Need Simple Ones
 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.
-
Jul 2nd, 2007, 09:55 AM
#17
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..
-
Jul 2nd, 2007, 07:01 PM
#18
Re: [2005] RegEx Need Simple Ones
The Regex man strikes back.... should handle all three cases...
vb Code:
Dim s As String = ""
Dim Pattern As String = "^[\d]*$|^[a-zA-Z]*$|^[\s]{0}$"
If System.Text.RegularExpressions.Regex.IsMatch(s, Pattern) = True Then
MessageBox.Show("Match!")
Else
MessageBox.Show("No Match!")
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|