diff --git a/src/outlines/types/__init__.py b/src/outlines/types/__init__.py index a81143b2e..97e3e99bf 100644 --- a/src/outlines/types/__init__.py +++ b/src/outlines/types/__init__.py @@ -117,8 +117,8 @@ def __getattr__(self, name): r"[a-fA-F0-9]{12}" ) ipv4 = Regex( - r"((25[0-5]|2[0-4][0-9]|1?[0-9]{1,2})\.){3}" - r"(25[0-5]|2[0-4][0-9]|1?[0-9]{1,2})" + r"((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.){3}" + r"(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])" ) # SemVer 2.0.0: https://semver.org/ diff --git a/tests/types/test_custom_types.py b/tests/types/test_custom_types.py index ae2fa5aea..5fda51238 100644 --- a/tests/types/test_custom_types.py +++ b/tests/types/test_custom_types.py @@ -98,6 +98,10 @@ (types.ipv4, "1.2.256.3", False), (types.ipv4, "1.2.3.256", False), (types.ipv4, "1.2.3", False), + (types.ipv4, "01.1.1.1", False), + (types.ipv4, "00.0.0.0", False), + (types.ipv4, "1.02.3.4", False), + (types.ipv4, "1.1.1.09", False), (types.ipv4, "1.2.3.4.5", False), (types.ipv4, "1.2.3.4.", False), (types.ipv4, ".1.2.3.4", False),