vb.net正则判断ip端口格式
作者:admin 日期:2023-06-22
Dim ip As String = "192.168.0.1"
' 创建正则表达式对象
Dim regex As New System.Text.RegularExpressions.Regex("^(\d{1,3}\.){3}\d{1,3}$")
' 判断是否是 IP 地址
If regex.IsMatch(ip) Then
Console.WriteLine("The string is an IP address.")
Else
Console.WriteLine("The string is not an IP address.")
End If
Dim ipAndPort As String = "192.168.0.1:8080"
' 创建正则表达式对象
Dim regex As New System.Text.RegularExpressions.Regex("^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:\d+$")
' 判断是否是 IP 地址加端口
If regex.IsMatch(ipAndPort) Then
Console.WriteLine("The string is an IP address with port.")
Else
Console.WriteLine("The string is not an IP address with port.")
End If
广告位