regular expression for ipaddress and mac address

前端 未结 7 1466
耶瑟儿~
耶瑟儿~ 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:54

    consider s=256.1.1.1 i'd like to make a little modification from Michal's answer:

    def find_ip(s):
        part = '(2[0-4]|1[0-9]|[0-9])?[0-9]|25[0-5]'
        res =re.search(r'(^| )((%s)\.){3}(%s)' %(part,part), s,re.I )
        if res:
            return res.group().strip()
        else:
            return ''
    

    notice '(^| )' means line start or space ahead, to avoid get '56.1.1.1' from '256.1.1.1'

    0 讨论(0)
提交回复
热议问题