regular expression for ipaddress and mac address

前端 未结 7 1464
耶瑟儿~
耶瑟儿~ 2021-01-06 05:59

can anyone suggest me the regular expression for ip address and mac address ?

i am using python & django

for example , http://[ipaddress]/SaveData/127.0.

7条回答
  •  醉梦人生
    2021-01-06 06:43

    You can use /^([0-2]?\d{0,2}\.){3}([0-2]?\d{0,2})$/ for IPv4 Address and /^([\da-fA-F]{1,4}:){7}([\da-fA-F]{1,4})$/i for IPv6 address.

    You can combine these two as /^((([0-2]?\d{0,2}\.){3}([0-2]?\d{0,2}))|(([\da-fA-F]{1,4}:){7}([\da-fA-F]{1,4})))$/i. You can find a sample here.

    Ref: http://snipplr.com/view/49994/ipv4-regex/, http://snipplr.com/view/49993/ipv6-regex/

    For Mac Address You can use /^([0-9A-F]{2}[-:]){5}[0-9A-F]{2}$/i. You can find a sample here.

提交回复
热议问题