473,385 Members | 1,641 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Regex Number Check

Should not the following return False if s="255xxxxyyy"? It seems to return
True.

Regex.IsMatch(s, "[0-9]")
--
Dennis in Houston
Nov 21 '05 #1
5 2245
Yes, it should return false.

'-- Check for number
Regex.IsMatch(s, "^\d+$")
"Dennis" <De****@discussions.microsoft.com> wrote in message
news:4E**********************************@microsof t.com...
Should not the following return False if s="255xxxxyyy"? It seems to
return
True.

Regex.IsMatch(s, "[0-9]")
--
Dennis in Houston

Nov 21 '05 #2
?Thanks for reply. Which one should return false, the one you send
(Regex.IsMatch(s, "^\d+$") or mine (Regex.IsMatch(s, "[0-9]")? Mine returns
true in VB.net 2003.

"Dr Screwup" wrote:
Yes, it should return false.

'-- Check for number
Regex.IsMatch(s, "^\d+$")
"Dennis" <De****@discussions.microsoft.com> wrote in message
news:4E**********************************@microsof t.com...
Should not the following return False if s="255xxxxyyy"? It seems to
return
True.

Regex.IsMatch(s, "[0-9]")
--
Dennis in Houston


Nov 21 '05 #3
Mine should be true for this: s = "1293" and false for this s= "255xxxxyyy.
Yours will return true for anything except this s="ABC" (anything without a
number).
"Dennis" <De****@discussions.microsoft.com> wrote in message
news:0A**********************************@microsof t.com...
?Thanks for reply. Which one should return false, the one you send
(Regex.IsMatch(s, "^\d+$") or mine (Regex.IsMatch(s, "[0-9]")? Mine
returns
true in VB.net 2003.

"Dr Screwup" wrote:
Yes, it should return false.

'-- Check for number
Regex.IsMatch(s, "^\d+$")
"Dennis" <De****@discussions.microsoft.com> wrote in message
news:4E**********************************@microsof t.com...
> Should not the following return False if s="255xxxxyyy"? It seems to
> return
> True.
>
> Regex.IsMatch(s, "[0-9]")
> --
> Dennis in Houston


Nov 21 '05 #4
Thanks. I guess I really had it wrong. I got the Regex string from one of
the previous notes on this newsgroup.

"Dr Screwup" wrote:
Mine should be true for this: s = "1293" and false for this s= "255xxxxyyy.
Yours will return true for anything except this s="ABC" (anything without a
number).
"Dennis" <De****@discussions.microsoft.com> wrote in message
news:0A**********************************@microsof t.com...
?Thanks for reply. Which one should return false, the one you send
(Regex.IsMatch(s, "^\d+$") or mine (Regex.IsMatch(s, "[0-9]")? Mine
returns
true in VB.net 2003.

"Dr Screwup" wrote:
Yes, it should return false.

'-- Check for number
Regex.IsMatch(s, "^\d+$")
"Dennis" <De****@discussions.microsoft.com> wrote in message
news:4E**********************************@microsof t.com...
> Should not the following return False if s="255xxxxyyy"? It seems to
> return
> True.
>
> Regex.IsMatch(s, "[0-9]")
> --
> Dennis in Houston


Nov 21 '05 #5
Dennis,
Should not the following return False if s="255xxxxyyy"? It seems to
return
True.

Regex.IsMatch(s, "[0-9]") If you try it, you will find it returns True, as you are looking for a
single digit 0 thru 9 anyplace in the input string. The string "255xxxxyyy"
contains 3 matches, the first 2, the first 5 & the second 5.

While: Regex.IsMatch(s, "^\d+$") Will return false for "255xxxxyyy", as you are looking for the beginning of
the string "^", followed by one or more digits "\d+", followed by the end of
the string "$".

For example, try the following code for both patterns:

Imports System.Text.RegularExpressions

Const theFirstPattern As String = "[0-9]"
Const theSecondPattern As String = "^\d+$"
Const input As String = "255xxxxyyy"

Dim theFirstRegex As New Regex(theFirstPattern)
Debug.WriteLine(theFirstRegex.IsMatch(input), "first is match")
For Each aMatch As Match In theFirstRegex.Matches(input)
Debug.WriteLine(aMatch.Value, aMatch.Index.ToString())
Next

Dim theSecondRegex As New Regex(theSecondPattern)
Debug.WriteLine(theSecondRegex.IsMatch(input), "second is match")
For Each aMatch As Match In theSecondRegex.Matches(input)
Debug.WriteLine(aMatch.Value, aMatch.Index.ToString())
Next

The following site provides a good overview of regular expressions:

http://www.regular-expressions.info/

While this site provides the syntax specifically supported by .NET:

http://msdn.microsoft.com/library/de...geElements.asp

Hope this helps
Jay

"Dennis" <De****@discussions.microsoft.com> wrote in message
news:4E**********************************@microsof t.com... Should not the following return False if s="255xxxxyyy"? It seems to
return
True.

Regex.IsMatch(s, "[0-9]")
--
Dennis in Houston

Nov 21 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Christ | last post by:
Hi there, i'm trying to make a regex, but it ain't working. In just one regex expression I want to check a password that must meet following requirements: - at least 6 characters long - at...
8
by: Johnny | last post by:
I need to determine whether a text box contains a value that does not convert to a decimal. If the value does not convert to a decimal, I want to throw a MessageBox to have the user correct the...
4
by: aevans1108 | last post by:
expanding this message to microsoft.public.dotnet.xml Greetings Please direct me to the right group if this is an inappropriate place to post this question. Thanks. I want to format a...
9
by: Tim Conner | last post by:
Is there a way to write a faster function ? public static bool IsNumber( char Value ) { if (Regex.IsMatch( Value.ToString(), @"^+$" )) { return true; } else return false; }
8
by: vbmark | last post by:
I'm new to RegEx in vb.net so I'm not sure how to do this. I want to know if a string contains two minus signs "-". If there are two then I want it to return TRUE. I also need to know if the...
3
by: jg | last post by:
I made a mistake somewhere in my vb code and I look, check and read against the articles and help on regex, I still can't find the mistake I made. I know my test string and the test patterns...
24
by: cassetti | last post by:
Here's the issue: I have roughly 20 MS excel spreadsheets, each row contains a record. These records were hand entered by people in call centers. The problem is, there can and are duplicate...
7
by: MattMika | last post by:
Can anyone point out the problem with this? The commented regex var and if statement dont work and break the GroupName check when uncommented. I tested the AccessCodeRegxp with preg_match and it...
1
by: TumurS | last post by:
Hi! I need to parse an input string. The string must consist of 1, 2 or 3 float numbers separated with blanks: Regex r = new Regex(@"^\s*(?<x>+)(\s+(?<y>+)(\s+(?<z>+))*)*\s*$",...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.