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/d...l/cpconRegularExpressionsLanguageElements.asp
Hope this helps
Jay
Dennis said:
Should not the following return False if s="255xxxxyyy"? It seems to
return
True.
Regex.IsMatch(s, "[0-9]")