VB.Net by API/System.Text.RegularExpressions/Regex — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
Admin (обсуждение | вклад) м (1 версия) |
(нет различий)
|
Текущая версия на 12:50, 26 мая 2010
Regex.IsMatch
Imports System.Text.RegularExpressions
Public Class Tester
Public Shared Sub Main
Dim testString As String
Dim emailPattern As String = _
"^([0-9a-zA-Z]+[-._+&])*[0-9a-zA-Z]+@" & _
"([-0-9a-zA-Z]+[.])+[a-zA-Z]{2,6}$"
testString = "a@nowhere.ru"
Console.WriteLine(testString & Space(3) & _
Regex.IsMatch(testString, emailPattern))
testString = "a@doe@mybad.ru"
Console.WriteLine(testString & Space(3) & _
Regex.IsMatch(testString, emailPattern))
End Sub
End Class
Regex.Matches
Imports System.Text.RegularExpressions
Public Class Tester
Public Shared Sub Main
Dim source As String = "This 7. several 0.9 numbers"
Dim parser As New Regex( _
"[-+]?([0-9]*\.)?[0-9]+([eE][-+]?[0-9]+)?")
Dim sourceMatches As MatchCollection = parser.Matches(source)
Dim result As Double = CDbl(sourceMatches(1).Value)
Console.WriteLine(result.ToString())
End Sub
End Class