Imports System
Imports System.Text.RegularExpressions
Module Regexprog
Sub Main()
Dim text As String = "ABC#123中文456def"
Dim pattern As String = "[\u4e00-\u9fa5]"
'匹配个数
Dim mc As MatchCollection = Regex.Matches(text, pattern)
Console.WriteLine("有{0}处匹配。", mc.Count)
'输出匹配值
For Each m As Match In mc
Console.WriteLine(m)
Next
'替换匹配值,替换为空
Dim rgx As New Regex(pattern)
Dim reSult As String = rgx.Replace(text, "")
Console.WriteLine(reSult)
'是否有匹配值
Dim exists As Boolean = rgx.IsMatch(text)
Console.WriteLine(exists)
Console.ReadKey()
End Sub
End Module
代码
输出结果