vb.net正则判断ip端口格式

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



上一篇: vb.net多线程下载
下一篇: vb.net判断重复文本并提取
文章来自: 本站原创
引用通告: 查看所有引用 | 我要引用此文章
Tags: vb.net
相关日志:
评论: 0 | 引用: 0 | 查看次数: 340
发表评论
昵 称:
密 码: 游客发言不需要密码.
邮 箱: 邮件地址支持Gravatar头像,邮箱地址不会公开.
网 址: 输入网址便于回访.
内 容:
验证码:
选 项:
虽然发表评论不用注册,但是为了保护您的发言权,建议您注册帐号.
字数限制 1000 字 | UBB代码 开启 | [img]标签 关闭

 广告位

↑返回顶部↑