re模块、正则匹配

mac2022-06-30  90

ip地址:

re.match( "^(\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])$", ip_addr)

域名

# 以Https、Http开头 re.match( "^(http|https?:\/\/)([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$", ip_addr )

端口号

([0-9]|[1-9]\d{1,3}|[1-5]\d{4}|6[0-4]\d{4}|65[0-4]\d{2}|655[0-2]\d|6553[0-5])

带有端口号的ip地址和域名

domain = re.match( r'^(http|https?:\/\/)([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?(:([0-9]|[1-9]\d{1,3}|[1-5]\d{4}|6[0-4]\d{4}|65[0-4]\d{2}|655[0-2]\d|6553[0-5]))?$', ip_addr) ip = re.match( r'^(\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])(:([0-9]|[1-9]\d{1,3}|[1-5]\d{4}|6[0-4]\d{4}|65[0-4]\d{2}|655[0-2]\d|6553[0-5]))?$', ip_addr)

用户名(大小写字母、数字、下划线和中文)

限制长度

^[\u4e00-\u9fa5_a-zA-Z0-9]{4,10}$

不限制长度

^[\u4e00-\u9fa5_a-zA-Z0-9]+$

不能以下划线开头和结尾

^(?!_)(?!.*?_$)[a-zA-Z0-9_\u4e00-\u9fa5]+$

中文字符

[\u4e00-\u9fa5]

匹配双字节字符(包括汉字在内)

[^\x00-\xff]

转载于:https://www.cnblogs.com/jiumo/p/11054513.html

相关资源:JAVA上百实例源码以及开源项目
最新回复(0)