Python 正则表达式验证特定范围的数字,IP地址端口正则表达式

# 0. 127.0.0.1 (ip:port)
'^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]):(6553[0-5]|655[0-2][0-9]|65[0-4][0-9]{2}|6[0-4][0-9]{3}|[1-5][0-9]{4}|[1-9][0-9]{1,3}|[0-9])$'

# 1. 1 to 12 (hour or month)
^(1[0-2]|[1-9])$
 
# 2. 1 to 24 (hour)
^(2[0-4]|1[0-9]|[1-9])$
 
# 3. 1 to 31 (day of the month)
^(3[01]|[12][0-9]|[1-9])$
 
# 4. 1 to 53 (week of the year)
^(5[0-3]|[1-4][0-9]|[1-9])$
 
# 5. 0 to 59 (minute or second)
^[1-5]?[0-9]$
 
# 6. 0 to 100 (percentage)
^(100|[1-9]?[0-9])$
 
# 7. 1 to 100 
^(100|[1-9][0-9]?)$
 
# 8. 32 to 126 (printable ASCII codes)
^(12[0-6]|1[01][0-9]|[4-9][0-9]|3[2-9])$
 
# 9. 0 to 127 (nonnegative signed byte)
^(12[0-7]|1[01][0-9]|[1-9]?[0-9])$
 
# 10. -128 to 127 (sinned byte)
^(12[0-7]|1[01][0-9]|[1-9]?[0-9]|-(12[08]|1[01][0-9]|[1-9]?[0-9]))$
 
# 11. 0 to 255 (unsigned byte)
^(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])$
 
# 12. 1 to 366 (day of the year)
^(36[0-6]|3[0-5][0-9]|[12][0-9]{2}|[1-9][0-9]?)$
 
# 13. 1900 to 2099 (year)
^(19|20)[0-9]{2}$
 
# 14. 0 to 32967 (nonnegative signed word)
^(3276[0-7]|327[0-5][0-9]|32[0-6][0-9]{2}|3[01][0-9]{3}|[12][0-9]{4}|[1-9][0-9]{1,3}|[0-9])$
 
# 15. -32768 to 32767 (signed word)
^(3276[0-7]|327[0-5][0-9]|32[0-6][0-9]{2}|3[01][0-9]{3}|[12][0-9]{4}|[1-9][0-9]{1,3}|[0-9]|-(3276[0-8]|327[0-5][0-9]|32[0-6][0-9]{2}|3[01][0-9]{3}|[12][0-9]{4}|[1-9][0-9]{1,3}|[0-9]))$
 
# 16. 0 to 65535 (unsigned word)
^(6553[0-5]|655[0-2][0-9]|65[0-4][0-9]{2}|6[0-4][0-9]{3}|[1-5][0-9]{4}|[1-9][0-9]{1,3}|[0-9])$

部分转载于:https://blog.csdn.net/guaguastd/article/details/39049843

对错误进行了修改!

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值