IP地址正则表达式python [英] IP address regex python

查看:167
本文介绍了IP地址正则表达式python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到正则表达式的问题,我需要最有效的正则表达式,
匹配IP地址,仅在255范围内。

I am having an issue with Regular expression, I need the most efficient regex that match IP address and in range of 255 only.

我试过这个 ip_pattern ='\ d {1,3} \。\\\ {1,3} \ 。\d {1,3} \.\d {1,3}',但它匹配偶数超过255的数字,例如321.222.11.4

I tried this one "ip_pattern = '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}'" , but it does match even numbers over 255, such as 321.222.11.4

推荐答案

这应该这样做:

^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$

这篇关于IP地址正则表达式python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆