「VB.NET」正規表現式で文字を範囲で指定する

2021年9月17日

書式
Public Function IsMatch (input As String) As Boolean
正規表現と一致する箇所が見つかった場合は true。それ以外の場合は false です。

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
Imports System.Text.RegularExpressions
Module Module1
Sub Main()
'文字を範囲で指定 X Y Zの文字を指定
Dim SK As String = "[X-Z]"
Dim resA As Boolean = Regex.IsMatch("ZERO", SK)
Console.WriteLine(resA)
'指定正規表現に一致するかどうか
Dim resB As Boolean = Regex.IsMatch("RST", SK)
Console.WriteLine(resB)
Console.ReadKey()
End Sub
End Module
Imports System.Text.RegularExpressions Module Module1 Sub Main() '文字を範囲で指定 X Y Zの文字を指定 Dim SK As String = "[X-Z]" Dim resA As Boolean = Regex.IsMatch("ZERO", SK) Console.WriteLine(resA) '指定正規表現に一致するかどうか Dim resB As Boolean = Regex.IsMatch("RST", SK) Console.WriteLine(resB) Console.ReadKey() End Sub End Module
Imports System.Text.RegularExpressions

Module Module1

    Sub Main()

        '文字を範囲で指定 X Y Zの文字を指定
        Dim SK As String = "[X-Z]"
        Dim resA As Boolean = Regex.IsMatch("ZERO", SK)
        Console.WriteLine(resA)


        '指定正規表現に一致するかどうか
        Dim resB As Boolean = Regex.IsMatch("RST", SK)
        Console.WriteLine(resB)

        Console.ReadKey()

    End Sub

End Module

実行結果
True
False

VB.net

Posted by arkgame