Implement `String#ipv4_address?`, which should return true if given object is an IPv4 address - four numbers (0-255) separated by dots.

It should only accept addresses in canonical representation, so no leading `0`s, spaces etc.

Source: codewars | Difficulty: EASY
Tags: Fundamentals

Starter code: def ipv4_address(address):
	

Solutions:
from re import compile, match
REGEX = compile('((\\d|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5])\\.){4}$')

def ipv4_address(address):
	return bool(match(REGEX, address + '.'))


import socket

def ipv4_address(address):
	try:
		socket.inet_pton(socket.AF_INET, address)
		return True
	except socket.error:
		return False


def ipv4_address(address):
	return address.count('.') == 3 and all([str.isdigit(s) and s == str(int(s)) and (int(s) >= 0) and (int(s) < 256) for s in address.split('.')])


def ipv4_address(address):
	addr = address.split('.')
	if len(addr) != 4:
		return False
	for e in addr:
		try:
			a = int(e)
			if a > 255 or a < 0:
				return False
			if str(a) != e:
				return False
		except:
			return False
	return True


ipv4_address = lambda address: bool(__import__('re').match('(([1-9]?\\d|1\\d\\d|2[0-4]\\d|25[0-5])(\\.(?!$)|$)){4}\\Z', address))


import re

def ipv4_address(address):
	return bool(re.match('((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])[.]){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\\Z', address))


from ipaddress import ip_address

def ipv4_address(address: str) -> bool:
	try:
		return len(str(ip_address(address))) == len(address)
	except ValueError:
		return False


from re import match

def ipv4_address(address):
	return bool(match('^(([1-9]?\\d|1\\d{2}|2([0-4]\\d|5[0-5]))(\\.(?!$)|$)){4}\\Z', address))


import re

def ipv4_address(address):
	return bool(re.match('\\d+(\\.\\d+){3}\\Z', address)) and all((0 <= int(x) <= 255 and (x == '0' or not x.startswith('0')) for x in re.findall('\\d+', address)))


import re

def ipv4_address(address):
	byte_reg = '(\\d|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5])'
	ipv4_regex = '\\A({0}[.]){{3}}{0}\\Z'.format(byte_reg)
	return bool(re.match(ipv4_regex, address))