1
import re
def ipv4_address(address):
    match = re.search(r"^((2[0-5][0-5]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(2[0-5][0-5]|1[0-9][0-9]|[1-9][0-9]|[0-9])$", address)   
    if match: return True
    else: return False

print(ipv4_address("127.0.0.1\n"))

I don`t understand why '$' is not working with '\n'

simpler test:

>>> bool(re.match("^ABC$","ABC\n"))
True
Jean-François Fabre
  • 137,073
  • 23
  • 153
  • 219

0 Answers0