VB.Net by API/System.Text.RegularExpressions/Regex

Материал из VB Эксперт
Перейти к: навигация, поиск

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