L3-Bataille-Navale/source/gui/regex.py

18 lines
602 B
Python

from math import inf
def number(min_length: int = 0, max_length: int = inf) -> str:
"""
Renvoie le regex correspondant à une suite de nombre.
:param min_length: la longueur minimum du nombre
:param max_length: la longueur maximum du nombre
:return: le regex correspondant
"""
return r"\d{%s,%s}" % (min_length, max_length if max_length < inf else "")
ipv4_check, ipv4_type = r"\d{1,3}(\.\d{1,3}){3}", r"[\d\.]{0,15}"
port_check, port_type = number(min_length=1, max_length=5), number(min_length=0, max_length=5)
username_check, username_type = r".{1,16}", r".{0,16}"