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.

Difficulty: introductory

Starter code:

def ipv4_address(address):
	

Solutions:
from re import compile, match

REGEX = compile(r'((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.){4}$')


def ipv4_address(address):
    # refactored thanks to @leonoverweel on CodeWars
    return bool(match(REGEX, address + '.'))


import socket
def ipv4_address(address):
    try: # No need to do work that's already been done
        socket.inet_pton(socket.AF_INET,address)
        return True
    except socket.error: # Better to ask forgiveness than permission
        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(r'^(([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(r'\d+(\.\d+){3}\Z', address))
        and all(0 <= int(x) <= 255 and (x == '0' or not x.startswith('0')) for x in re.findall(r'\d+', address))
    )

import re

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