「VB.NET」Regex クラスのサンプル

2021年9月10日

説明
Public Class Regex Implements ISerializable
変更不可の正規表現を表します。

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
Imports System.Text.RegularExpressions
Module Module1
Sub Main()
Dim strA As String = "1234||5678"
'4桁の数字正規表現式
Dim target As New Regex("[0-9]{4}")
Console.WriteLine("置換前文字列: " + strA)
'文字sまたはtを123に置換
Console.WriteLine("置換後文字列: " + target.Replace(strA, "****"))
Console.ReadKey()
End Sub
End Module
Imports System.Text.RegularExpressions Module Module1 Sub Main() Dim strA As String = "1234||5678" '4桁の数字正規表現式 Dim target As New Regex("[0-9]{4}") Console.WriteLine("置換前文字列: " + strA) '文字sまたはtを123に置換 Console.WriteLine("置換後文字列: " + target.Replace(strA, "****")) Console.ReadKey() End Sub End Module
Imports System.Text.RegularExpressions
Module Module1

    Sub Main()
        Dim strA As String = "1234||5678"
        '4桁の数字正規表現式
        Dim target As New Regex("[0-9]{4}")


        Console.WriteLine("置換前文字列: " + strA)
        '文字sまたはtを123に置換
        Console.WriteLine("置換後文字列: " + target.Replace(strA, "****"))

        Console.ReadKey()

    End Sub

End Module

結果
置換前文字列: 1234||5678
置換後文字列: ****||****

VB.net

Posted by arkgame