Решение на Регулярни изрази от Георги Стайков

Обратно към всички решения

Към профила на Георги Стайков

Резултати

  • 8 точки от тестове
  • 0 бонус точки
  • 8 точки общо
  • 32 успешни тест(а)
  • 7 неуспешни тест(а)

Код

import re
class PrivacyFilter:
def __init__(self, text):
self.text = text
self.preserve_email_hostname = False
self.preserve_phone_country_code = False
self.partially_preserve_email_username = False
def validate_email(self):
text = self.text
if self.partially_preserve_email_username:
self.preserve_email_hostname = True
text = re.sub(r"\b([a-z0-9]([\w\+\.-]){2})([\w\+\.-]){3,198}(@"
r"([a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?\.)+"
r"[a-z]{2,3}(\.[a-z]{2})?)\b",
r'\1[FILTERED]\4', text, flags=re.IGNORECASE)
if self.preserve_email_hostname:
return re.sub(r"\b[a-z0-9]([\w\+\.-]){0,200}(@"
r"([a-z0-9]([a-z0-9-]{0,61}"
r"[a-z0-9])?\.)+[a-z]{2,3}(\.[a-z]{2})?)\b",
r'[FILTERED]\2', text, flags=re.IGNORECASE)
return re.sub(r"\b[a-z0-9]([\w\+\.-]){0,200}@"
r"([a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?\.)+"
r"[a-z]{2,3}(\.[a-z]{2})?\b",
'[EMAIL]', self.text, flags=re.IGNORECASE)
def validate_phone(self, text):
if self.preserve_phone_country_code:
text = re.sub(r"((\b00|\+)[1-9][0-9]{0,2})"
r"([-\s\(\)]{0,2}\d){6,11}\b",
r'\1 [FILTERED]', text, flags=re.IGNORECASE)
return re.sub(r"((\b0[1-9])([-\s\(\)]{0,2}\d){5,10}\b)|"
r"((\b0[-\s\(\)]{1,2})(\d[-\s\(\)]{0,2}){5,10}\d\b)|"
r"(((\b00|\+)[1-9][0-9]{0,2})"
r"([-\s\(\)]{0,2}\d){6,11}\b)",
'[PHONE]', text, flags=re.IGNORECASE)
def filtered(self):
return self.validate_phone(self.validate_email())
class Validations:
@classmethod
def is_email(cls, value):
return not re.match(r"^\b[a-z0-9]([\w\+\.-]){0,200}@"
r"([a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?\.)+"
r"[a-z]{2,3}(\.[a-z]{2})?\b$",
value, flags=re.IGNORECASE) is None
@classmethod
def is_phone(cls, value):
return not re.match(r"^\b((0[1-9])([-\s\(\)]{0,2}\d){5,10})|"
r"((0[-\s\(\)]{1,2})(\d[-\s\(\)]{0,2}){5,10}\d)|"
r"(((00|\+)[1-9][0-9]{0,2})"
r"([-\s\(\)]{0,2}\d){6,11})\b$",
value, flags=re.IGNORECASE) is None
@classmethod
def is_hostname(cls, value):
return not re.match(r"^\b([a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?\.)+"
r"[a-z]{2,3}(\.[a-z]{2})?\b$",
value, flags=re.IGNORECASE) is None
@classmethod
def is_ip_address(cls, value):
number = r"(([0-9])|([1-9][0-9])|(1\d\d)|(2[0-4][0-9])|(25[0-5]))"
return not re.match(r"^\b(" + number + r"\.){3}" + number + r"\b$",
value, flags=re.IGNORECASE) is None
@classmethod
def is_number(cls, value):
return not re.match(r"^-?(0|[1-9][0-9]*)(\.\d+)?$",
value, flags=re.IGNORECASE) is None
@classmethod
def is_integer(cls, value):
return not re.match(r"^-?(0|[1-9][0-9]*)$",
value, flags=re.IGNORECASE) is None
@classmethod
def is_date(cls, value):
return not re.match(r"^\b([0-9]){4}-((0[1-9])|(1[0-2]))-"
r"((0[1-9])|([1-2][0-9])|(3[0-1]))\b$",
value, flags=re.IGNORECASE) is None
@classmethod
def is_time(cls, value):
return not re.match(r"^\b((0[0-9])|(1[0-9])|(2[0-3])):"
r"((0[0-9])|([1-5][0-9])):"
r"((0[0-9])|([1-5][0-9]))\b$",
value, flags=re.IGNORECASE) is None
@classmethod
def is_datetime(cls, value):
return not re.match(r"^\b([0-9]){4}-((0[1-9])|(1[0-2]))-"
r"((0[1-9])|([1-2][0-9])|(3[0-1]))[\sT]"
r"((0[0-9])|(1[0-9])|(2[0-3])):"
r"((0[0-9])|([1-5][0-9])):"
r"((0[0-9])|([1-5][0-9]))\b$",
value, flags=re.IGNORECASE) is None

Лог от изпълнението

....F...........F....FFF..FF...........
======================================================================
FAIL: test_does_not_filter_invalid_phone_numbers (test.PrivacyFilterTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140513-11348-mdl0rt/test.py", line 86, in test_does_not_filter_invalid_phone_numbers
    self.assertEqual(filtered, solution.PrivacyFilter(text).filtered())
AssertionError: 'Reach me at: 0885123' != 'Reach me at: [PHONE]'
- Reach me at: 0885123
+ Reach me at: [PHONE]


======================================================================
FAIL: test_can_validate_more_complex_phone_numbers (test.ValidationsTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140513-11348-mdl0rt/test.py", line 160, in test_can_validate_more_complex_phone_numbers
    self.assertIs(solution.Validations.is_phone(phone), valid)
AssertionError: True is not False

======================================================================
FAIL: test_does_not_break_on_phones_in_multiline_strings (test.ValidationsTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140513-11348-mdl0rt/test.py", line 163, in test_does_not_break_on_phones_in_multiline_strings
    self.assertFalse(solution.Validations.is_phone("0885123123\nwat?"))
AssertionError: True is not false

======================================================================
FAIL: test_handles_multiline_strings_in_IP_validation_properly (test.ValidationsTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140513-11348-mdl0rt/test.py", line 189, in test_handles_multiline_strings_in_IP_validation_properly
    self.assertFalse(solution.Validations.is_ip_address("8.8.8.8\n"))
AssertionError: True is not false

======================================================================
FAIL: test_handles_multiline_strings_in_hostname_validation_properly (test.ValidationsTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140513-11348-mdl0rt/test.py", line 179, in test_handles_multiline_strings_in_hostname_validation_properly
    self.assertFalse(solution.Validations.is_hostname("foo.com\n"))
AssertionError: True is not false

======================================================================
FAIL: test_handles_newlines_in_date_validation (test.ValidationsTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140513-11348-mdl0rt/test.py", line 259, in test_handles_newlines_in_date_validation
    self.assertFalse(solution.Validations.is_date("2012-11-19\n"))
AssertionError: True is not false

======================================================================
FAIL: test_handles_newlines_in_time_and_datetime_validation (test.ValidationsTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140513-11348-mdl0rt/test.py", line 288, in test_handles_newlines_in_time_and_datetime_validation
    self.assertFalse(solution.Validations.is_time("12:01:01\n"))
AssertionError: True is not false

----------------------------------------------------------------------
Ran 39 tests in 0.057s

FAILED (failures=7)

История (3 версии и 2 коментара)

Георги обнови решението на 20.04.2014 01:51 (преди над 10 години)

+import re
+
+
+class PrivacyFilter:
+ preserve_email_hostname = False
+ preserve_phone_country_code = False
+ partially_preserve_email_username = False
+
+ def __init__(self, text=""):
+ self.text = text
+ self.preserve_email_hostname = False
+ self.preserve_phone_country_code = False
+ self.partially_preserve_email_username = False
+
+ def validate_email(self):
+ text = self.text
+ if self.partially_preserve_email_username:
+ self.preserve_email_hostname = True
+ text = re.sub(r"\b([a-z0-9]([\w\+\.-]){2})([\w\+\.-]){3,198}(@"
+ r"([a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?\.)+"
+ r"[a-z]{2,3}(\.[a-z]{2})?)\b",
+ r'\1[FILTERED]\4', text, flags=re.IGNORECASE)
+ if self.preserve_email_hostname:
+ return re.sub(r"\b[a-z0-9]([\w\+\.-]){0,200}(@"
+ r"([a-z0-9]([a-z0-9-]{0,61}"
+ r"[a-z0-9])?\.)+[a-z]{2,3}(\.[a-z]{2})?)\b",
+ r'[FILTERED]\2', text, flags=re.IGNORECASE)
+
+ return re.sub(r"\b[a-z0-9]([\w\+\.-]){0,200}@"
+ r"([a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?\.)+"
+ r"[a-z]{2,3}(\.[a-z]{2})?\b",
+ '[EMAIL]', self.text, flags=re.IGNORECASE)
+
+ def validate_phone(self, text):
+ if self.preserve_phone_country_code:
+ text = re.sub(r"((\b00|\+)[1-9][0-9]{0,2})[-\s\(\)]"
+ r"{0,2}[1-9]([-\s\(\)]{0,2}\d){5,11}\b",
+ r'\1 [FILTERED]', text, flags=re.IGNORECASE)
+
+ return re.sub(r"((\b0)|((\b00|\+)[1-9][0-9]{0,2}))[-\s\(\)]"
+ r"{0,2}[1-9]([-\s\(\)]{0,2}\d){5,11}\b",
+ '[PHONE]', text, flags=re.IGNORECASE)
+
+ def filtered(self):
+ return self.validate_phone(self.validate_email())
+
+
+class Validations:
+
+ @classmethod
+ def is_email(cls, value):
+ return not re.match(r"^[a-z0-9]([\w\+\.-]){0,200}@"
+ r"([a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?\.)+"
+ r"[a-z]{2,3}(\.[a-z]{2})?$",
+ value, flags=re.IGNORECASE) is None
+
+ @classmethod
+ def is_phone(cls, value):
+ return not re.match(r"^((0)|((00|\+)[1-9][0-9]{0,2}))[-\s\(\)]"
+ r"{0,2}[1-9]([-\s\(\)]{0,2}\d){5,11}$",
+ value, flags=re.IGNORECASE) is None
+
+ @classmethod
+ def is_hostname(cls, value):
+ return not re.match(r"^([a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?\.)+"
+ r"[a-z]{2,3}(\.[a-z]{2})?$",
+ value, flags=re.IGNORECASE) is None
+
+ @classmethod
+ def is_ip_address(cls, value):
+ number = r"(([0-9])|([1-9][0-9])|(1\d\d)|(2[0-4][0-9])|(25[0-5]))"
+ return not re.match(r"^(" + number + r"\.){3}" + number + "$",
+ value, flags=re.IGNORECASE) is None
+
+ @classmethod
+ def is_number(cls, value):
+ return not re.match(r"^-?(0|[1-9][0-9]*)(\.\d+)?$",
+ value, flags=re.IGNORECASE) is None
+
+ @classmethod
+ def is_integer(cls, value):
+ return not re.match(r"^-?(0|[1-9][0-9]*)$",
+ value, flags=re.IGNORECASE) is None
+
+ @classmethod
+ def is_date(cls, value):
+ return not re.match(r"^([0-9]){4}-((0[1-9])|(1[0-2]))-"
+ r"((0[1-9])|([1-2][0-9])|(3[0-1]))$",
+ value, flags=re.IGNORECASE) is None
+
+ @classmethod
+ def is_time(cls, value):
+ return not re.match(r"^((0[0-9])|(1[0-9])|(2[0-3])):"
+ r"((0[0-9])|([1-5][0-9])):"
+ r"((0[0-9])|([1-5][0-9]))$",
+ value, flags=re.IGNORECASE) is None
+
+ @classmethod
+ def is_datetime(cls, value):
+ return not re.match(r"^([0-9]){4}-((0[1-9])|(1[0-2]))-"
+ r"((0[1-9])|([1-2][0-9])|(3[0-1]))[\sT]"
+ r"((0[0-9])|(1[0-9])|(2[0-3])):"
+ r"((0[0-9])|([1-5][0-9])):"
+ r"((0[0-9])|([1-5][0-9]))$",
+ value, flags=re.IGNORECASE) is None

Георги обнови решението на 21.04.2014 01:51 (преди над 10 години)

import re
class PrivacyFilter:
- preserve_email_hostname = False
- preserve_phone_country_code = False
- partially_preserve_email_username = False
- def __init__(self, text=""):
+ def __init__(self, text):
self.text = text
self.preserve_email_hostname = False
self.preserve_phone_country_code = False
self.partially_preserve_email_username = False
def validate_email(self):
text = self.text
if self.partially_preserve_email_username:
self.preserve_email_hostname = True
text = re.sub(r"\b([a-z0-9]([\w\+\.-]){2})([\w\+\.-]){3,198}(@"
r"([a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?\.)+"
r"[a-z]{2,3}(\.[a-z]{2})?)\b",
r'\1[FILTERED]\4', text, flags=re.IGNORECASE)
if self.preserve_email_hostname:
return re.sub(r"\b[a-z0-9]([\w\+\.-]){0,200}(@"
r"([a-z0-9]([a-z0-9-]{0,61}"
r"[a-z0-9])?\.)+[a-z]{2,3}(\.[a-z]{2})?)\b",
r'[FILTERED]\2', text, flags=re.IGNORECASE)
return re.sub(r"\b[a-z0-9]([\w\+\.-]){0,200}@"
r"([a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?\.)+"
r"[a-z]{2,3}(\.[a-z]{2})?\b",
'[EMAIL]', self.text, flags=re.IGNORECASE)
def validate_phone(self, text):
if self.preserve_phone_country_code:
text = re.sub(r"((\b00|\+)[1-9][0-9]{0,2})[-\s\(\)]"
- r"{0,2}[1-9]([-\s\(\)]{0,2}\d){5,11}\b",
+ r"{0,2}[1-9]([-\s\(\)]{0,2}\d){5,10}\b",
r'\1 [FILTERED]', text, flags=re.IGNORECASE)
return re.sub(r"((\b0)|((\b00|\+)[1-9][0-9]{0,2}))[-\s\(\)]"
- r"{0,2}[1-9]([-\s\(\)]{0,2}\d){5,11}\b",
+ r"{0,2}[1-9]([-\s\(\)]{0,2}\d){5,10}\b",
'[PHONE]', text, flags=re.IGNORECASE)
def filtered(self):
return self.validate_phone(self.validate_email())
class Validations:
@classmethod
def is_email(cls, value):
return not re.match(r"^[a-z0-9]([\w\+\.-]){0,200}@"
r"([a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?\.)+"
r"[a-z]{2,3}(\.[a-z]{2})?$",
value, flags=re.IGNORECASE) is None
@classmethod
def is_phone(cls, value):
return not re.match(r"^((0)|((00|\+)[1-9][0-9]{0,2}))[-\s\(\)]"
- r"{0,2}[1-9]([-\s\(\)]{0,2}\d){5,11}$",
+ r"{0,2}[1-9]([-\s\(\)]{0,2}\d){5,10}$",
value, flags=re.IGNORECASE) is None
@classmethod
def is_hostname(cls, value):
return not re.match(r"^([a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?\.)+"
r"[a-z]{2,3}(\.[a-z]{2})?$",
value, flags=re.IGNORECASE) is None
@classmethod
def is_ip_address(cls, value):
number = r"(([0-9])|([1-9][0-9])|(1\d\d)|(2[0-4][0-9])|(25[0-5]))"
return not re.match(r"^(" + number + r"\.){3}" + number + "$",
value, flags=re.IGNORECASE) is None
@classmethod
def is_number(cls, value):
return not re.match(r"^-?(0|[1-9][0-9]*)(\.\d+)?$",
value, flags=re.IGNORECASE) is None
@classmethod
def is_integer(cls, value):
return not re.match(r"^-?(0|[1-9][0-9]*)$",
value, flags=re.IGNORECASE) is None
@classmethod
def is_date(cls, value):
return not re.match(r"^([0-9]){4}-((0[1-9])|(1[0-2]))-"
r"((0[1-9])|([1-2][0-9])|(3[0-1]))$",
value, flags=re.IGNORECASE) is None
@classmethod
def is_time(cls, value):
return not re.match(r"^((0[0-9])|(1[0-9])|(2[0-3])):"
r"((0[0-9])|([1-5][0-9])):"
r"((0[0-9])|([1-5][0-9]))$",
value, flags=re.IGNORECASE) is None
@classmethod
def is_datetime(cls, value):
return not re.match(r"^([0-9]){4}-((0[1-9])|(1[0-2]))-"
r"((0[1-9])|([1-2][0-9])|(3[0-1]))[\sT]"
r"((0[0-9])|(1[0-9])|(2[0-3])):"
r"((0[0-9])|([1-5][0-9])):"
r"((0[0-9])|([1-5][0-9]))$",
value, flags=re.IGNORECASE) is None

Не разбирам какво имаш в предвид. Нали на валидаторите се подава някакъв стринг и валидаторът трябва да прецени дали стринга е валидно Х (нещо) или не е валидно Х ? Какъв е този специален случай и защо ми е \b след като стринга или е валиден телефон или не е валиден телефон (примерно) и няма думи преди и след него,защо ми е разделител за думи (\b) ? Или идеята ти е че на валидаторите може да се подава цяло изречение и валидатора да преценя дали в изречението има валиден телефон ? Това не ми се струва правилно, защото тъй като валидатора връща True/False ние трябва да го питаме за конкретно нещо не за цяло изречение. И като цяло името на валидатора говори за това - подадения стринг телефон ли е или не. А не подаденото изречение телефон ли е или не, защото най-малкото звучи нелогично ?

П.П Тоест идеята е регулярния ми израз за телефон да стане -> \bрегулярният ми израз за телефон\b ?

П.П2 А иначе като цяло регулярните ми изрази ОК ли са ?

Георги обнови решението на 23.04.2014 00:45 (преди над 10 години)

import re
class PrivacyFilter:
def __init__(self, text):
self.text = text
self.preserve_email_hostname = False
self.preserve_phone_country_code = False
self.partially_preserve_email_username = False
def validate_email(self):
text = self.text
if self.partially_preserve_email_username:
self.preserve_email_hostname = True
text = re.sub(r"\b([a-z0-9]([\w\+\.-]){2})([\w\+\.-]){3,198}(@"
r"([a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?\.)+"
r"[a-z]{2,3}(\.[a-z]{2})?)\b",
r'\1[FILTERED]\4', text, flags=re.IGNORECASE)
if self.preserve_email_hostname:
return re.sub(r"\b[a-z0-9]([\w\+\.-]){0,200}(@"
r"([a-z0-9]([a-z0-9-]{0,61}"
r"[a-z0-9])?\.)+[a-z]{2,3}(\.[a-z]{2})?)\b",
r'[FILTERED]\2', text, flags=re.IGNORECASE)
return re.sub(r"\b[a-z0-9]([\w\+\.-]){0,200}@"
r"([a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?\.)+"
r"[a-z]{2,3}(\.[a-z]{2})?\b",
'[EMAIL]', self.text, flags=re.IGNORECASE)
def validate_phone(self, text):
if self.preserve_phone_country_code:
- text = re.sub(r"((\b00|\+)[1-9][0-9]{0,2})[-\s\(\)]"
- r"{0,2}[1-9]([-\s\(\)]{0,2}\d){5,10}\b",
+ text = re.sub(r"((\b00|\+)[1-9][0-9]{0,2})"
+ r"([-\s\(\)]{0,2}\d){6,11}\b",
r'\1 [FILTERED]', text, flags=re.IGNORECASE)
- return re.sub(r"((\b0)|((\b00|\+)[1-9][0-9]{0,2}))[-\s\(\)]"
- r"{0,2}[1-9]([-\s\(\)]{0,2}\d){5,10}\b",
+ return re.sub(r"((\b0[1-9])([-\s\(\)]{0,2}\d){5,10}\b)|"
+ r"((\b0[-\s\(\)]{1,2})(\d[-\s\(\)]{0,2}){5,10}\d\b)|"
+ r"(((\b00|\+)[1-9][0-9]{0,2})"
+ r"([-\s\(\)]{0,2}\d){6,11}\b)",
'[PHONE]', text, flags=re.IGNORECASE)
def filtered(self):
return self.validate_phone(self.validate_email())
class Validations:
@classmethod
def is_email(cls, value):
- return not re.match(r"^[a-z0-9]([\w\+\.-]){0,200}@"
+ return not re.match(r"^\b[a-z0-9]([\w\+\.-]){0,200}@"
r"([a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?\.)+"
- r"[a-z]{2,3}(\.[a-z]{2})?$",
+ r"[a-z]{2,3}(\.[a-z]{2})?\b$",
value, flags=re.IGNORECASE) is None
@classmethod
def is_phone(cls, value):
- return not re.match(r"^((0)|((00|\+)[1-9][0-9]{0,2}))[-\s\(\)]"
- r"{0,2}[1-9]([-\s\(\)]{0,2}\d){5,10}$",
+ return not re.match(r"^\b((0[1-9])([-\s\(\)]{0,2}\d){5,10})|"
+ r"((0[-\s\(\)]{1,2})(\d[-\s\(\)]{0,2}){5,10}\d)|"
+ r"(((00|\+)[1-9][0-9]{0,2})"
+ r"([-\s\(\)]{0,2}\d){6,11})\b$",
value, flags=re.IGNORECASE) is None
@classmethod
def is_hostname(cls, value):
- return not re.match(r"^([a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?\.)+"
- r"[a-z]{2,3}(\.[a-z]{2})?$",
+ return not re.match(r"^\b([a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?\.)+"
+ r"[a-z]{2,3}(\.[a-z]{2})?\b$",
value, flags=re.IGNORECASE) is None
@classmethod
def is_ip_address(cls, value):
number = r"(([0-9])|([1-9][0-9])|(1\d\d)|(2[0-4][0-9])|(25[0-5]))"
- return not re.match(r"^(" + number + r"\.){3}" + number + "$",
+ return not re.match(r"^\b(" + number + r"\.){3}" + number + r"\b$",
value, flags=re.IGNORECASE) is None
@classmethod
def is_number(cls, value):
return not re.match(r"^-?(0|[1-9][0-9]*)(\.\d+)?$",
value, flags=re.IGNORECASE) is None
@classmethod
def is_integer(cls, value):
return not re.match(r"^-?(0|[1-9][0-9]*)$",
value, flags=re.IGNORECASE) is None
@classmethod
def is_date(cls, value):
- return not re.match(r"^([0-9]){4}-((0[1-9])|(1[0-2]))-"
- r"((0[1-9])|([1-2][0-9])|(3[0-1]))$",
+ return not re.match(r"^\b([0-9]){4}-((0[1-9])|(1[0-2]))-"
+ r"((0[1-9])|([1-2][0-9])|(3[0-1]))\b$",
value, flags=re.IGNORECASE) is None
@classmethod
def is_time(cls, value):
- return not re.match(r"^((0[0-9])|(1[0-9])|(2[0-3])):"
+ return not re.match(r"^\b((0[0-9])|(1[0-9])|(2[0-3])):"
r"((0[0-9])|([1-5][0-9])):"
- r"((0[0-9])|([1-5][0-9]))$",
+ r"((0[0-9])|([1-5][0-9]))\b$",
value, flags=re.IGNORECASE) is None
@classmethod
def is_datetime(cls, value):
- return not re.match(r"^([0-9]){4}-((0[1-9])|(1[0-2]))-"
+ return not re.match(r"^\b([0-9]){4}-((0[1-9])|(1[0-2]))-"
r"((0[1-9])|([1-2][0-9])|(3[0-1]))[\sT]"
r"((0[0-9])|(1[0-9])|(2[0-3])):"
r"((0[0-9])|([1-5][0-9])):"
- r"((0[0-9])|([1-5][0-9]))$",
+ r"((0[0-9])|([1-5][0-9]))\b$",
value, flags=re.IGNORECASE) is None
+