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.0.1/00-0C-F1-56-98-AD/
for mac address i tried following but didn't work
([0-9A-F]{2}[:-]){5}([0-9A-F]{2})
^([0-9A-F]{2}[:-]){5}([0-9A-F]{2})$
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.Place this snippet in your django routing definitions file -
urls.py
Your regular expression only contains two capturing groups (parentheses), so it isn't storing the entire address (the first group gets "overwritten"). Try these:
IP addresses get trickier because the ranges are binary but the representation is decimal.
consider s=256.1.1.1 i'd like to make a little modification from Michal's answer:
notice '(^| )' means line start or space ahead, to avoid get '56.1.1.1' from '256.1.1.1'
alright so this is what I use for IPV4
([0-9]{1,3}.){3}[0-9]{1,3}
tested with
127.0.0.1 255.255.255.255
and works for all
This is for MAC address: