Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import re
- def ipv4_address(ip):
- return (bool(re.match(
- '^(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]).){3}
- ([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])$', ip))
- if True else False)
- print(ipv4_address("127.0.0.1n"))
- A(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(?:.(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3}Z
- import re
- octet = r'(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])'
- rx = re.compile(r"A{0}(?:.{0}){{3}}Z".format(octet))
- def ipv4_address(ip):
- return bool(rx.match(ip))
- strs = ["127.0.0.1n","127.0.0.2"]
- for s in strs:
- print("'{}' => {}".format(s, ipv4_address(s)))
- '127.0.0.1
- ' => False
- '127.0.0.2' => True
Add Comment
Please, Sign In to add comment