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

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

Към профила на Емилиан Станков

Резултати

  • 6 точки от тестове
  • 0 бонус точки
  • 6 точки общо
  • 23 успешни тест(а)
  • 16 неуспешни тест(а)

Код

import re
class Validations():
@classmethod
def is_email(self, value):
host = r'([^\W_][a-zA-Z0-9-]{,62}[a-zA-Z0-9][.])+[a-zA-Z]{2,3}'
pattern = r'^[^\W_][\w+-.]{,200}@%s$' % host
return bool(re.search(pattern, value))
@classmethod
def is_hostname(self, value):
pattern = r'^([^\W_][a-zA-Z0-9-]{,62}[a-zA-Z0-9][.])+[a-zA-Z]{2,3}$'
return bool(re.search(pattern, value))
@classmethod
def is_phone(self, value):
pattern = r'^([0]|(\+|00)[1-9]{1,3})[ ()-]?[1-9]([ ()-]?[0-9]){5,10}$'
return bool(re.search(pattern, value))
@classmethod
def is_ip_address(self, value):
valid_number = r'(0|[1-9][0-9]|[1-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])'
pattern = r'^(%s.){3}%s$' % (valid_number, valid_number)
return bool(re.search(pattern, value))
@classmethod
def is_number(self, value):
pattern = r'^-?0$|^-?(0|[1-9][0-9]+)[.][0-9]+$|^-?[1-9][0-9]+$'
return bool(re.search(pattern, value))
@classmethod
def is_integer(self, value):
pattern = r'^-?0$|^-?[1-9][0-9]+$'
return bool(re.search(pattern, value))
@classmethod
def is_date(self, value):
pattern = r'^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$'
return bool(re.search(pattern, value))
@classmethod
def is_time(self, value):
pattern = r'^([0-1][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]$'
return bool(re.search(pattern, value))
@classmethod
def is_datetime(self, value):
date = r'[0-9]{4}-(0[1-9]|1[0-2])-([0-2][0-9]|3[01])'
time = r'([0-1][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]'
pattern = r'^%s[ T]%s$' % (date, time)
return bool(re.search(pattern, value))
class PrivacyFilter():
def __init__(self, text):
self.text = text
self.preserve_phone_country_code = False
self.preserve_email_hostname = False
self.partially_preserve_email_username = False
def filtered(self):
filtered = self.text
phone = r'(\b|\s)([0]|(\+|00)[1-9]{1,3})' \
r'[ ()-]?[1-9]([ ()-]?[0-9]){5,10}'
host = r'([^\W_][a-zA-Z0-9-]{,62}[a-zA-Z0-9][.])+[a-zA-Z]{2,3}'
email = r'[^\W_][\w+-.]{,200}(@%s)' % host
if self.preserve_phone_country_code:
filtered = re.sub(phone, r'\1\2%s' % ' [FILTERED]', filtered)
if self.preserve_email_hostname:
filtered = re.sub(email, r'%s\1' % '[FILTERED]', filtered)
if self.partially_preserve_email_username:
partial_email = r'([^\W_][\w+-.]{2})[\w+-.]{,197}(@%s)' % host
filtered = re.sub(partial_email,
r'\1%s\2' % '[FILTERED]', filtered)
filtered = re.sub(phone, r'\1%s' % '[PHONE]', filtered)
filtered = re.sub(email, '[EMAIL]', filtered)
return filtered

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

..FFFFFF..F.....F.....FF..FF...FF.F.F..
======================================================================
FAIL: test_does_not_brake_with_unicode (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-1mbn8id/test.py", line 64, in test_does_not_brake_with_unicode
    self.assertEqual('За връзка: [FILTERED]@example.com', self.partially_filter_email_usernames('За връзка: me@example.com'))
AssertionError: 'За връзка: [FILTERED]@example.com' != 'За връзка: [EMAIL]'
- За връзка: [FILTERED]@example.com
+ За връзка: [EMAIL]


======================================================================
FAIL: test_does_not_filter_invalid_emails (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-1mbn8id/test.py", line 48, in test_does_not_filter_invalid_emails
    self.assertEqual(text, solution.PrivacyFilter(text).filtered())
AssertionError: 'Contact me here: _invalid@email.com' != 'Contact me here: _[EMAIL]'
- Contact me here: _invalid@email.com
+ Contact me here: _[EMAIL]


======================================================================
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-1mbn8id/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_filters_more_complex_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-1mbn8id/test.py", line 76, in test_filters_more_complex_phone_numbers
    self.assertEqual(filtered, solution.PrivacyFilter(text).filtered())
AssertionError: '[PHONE]' != '+1 555 123-456'
- [PHONE]
+ +1 555 123-456


======================================================================
FAIL: test_filters_whole_email_usernames_if_too_short (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-1mbn8id/test.py", line 61, in test_filters_whole_email_usernames_if_too_short
    self.assertEqual('[FILTERED]@example.com', self.partially_filter_email_usernames('me@example.com'))
AssertionError: '[FILTERED]@example.com' != '[EMAIL]'
- [FILTERED]@example.com
+ [EMAIL]


======================================================================
FAIL: test_obfuscates_more_complicated_emails (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-1mbn8id/test.py", line 37, in test_obfuscates_more_complicated_emails
    self.assertEqual(filtered, solution.PrivacyFilter(text).filtered())
AssertionError: '[EMAIL]' != 'larodi@x.com'
- [EMAIL]
+ larodi@x.com


======================================================================
FAIL: test_separates_preserved_country_code_from_filtered_phone_with_a_space (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-1mbn8id/test.py", line 100, in test_separates_preserved_country_code_from_filtered_phone_with_a_space
    self.assertEqual(filtered, filter.filtered())
AssertionError: 'Phone: +25 [FILTERED]' != 'Phone: +25( 55 )12 12255'
- Phone: +25 [FILTERED]
+ Phone: +25( 55 )12 12255


======================================================================
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-1mbn8id/test.py", line 160, in test_can_validate_more_complex_phone_numbers
    self.assertIs(solution.Validations.is_phone(phone), valid)
AssertionError: False is not True

======================================================================
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-1mbn8id/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-1mbn8id/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-1mbn8id/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-1mbn8id/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

======================================================================
FAIL: test_validates_datetime_values (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-1mbn8id/test.py", line 282, in test_validates_datetime_values
    self.assertFalse(solution.Validations.is_datetime('2012-01-00T23:59:00'))
AssertionError: True is not false

======================================================================
FAIL: test_validates_hostnames (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-1mbn8id/test.py", line 169, in test_validates_hostnames
    self.assertTrue(solution.Validations.is_hostname('1.2.3.4.xip.io'))
AssertionError: False is not true

======================================================================
FAIL: test_validates_more_complex_integers (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-1mbn8id/test.py", line 227, in test_validates_more_complex_integers
    self.assertTrue(solution.Validations.is_integer('9'))
AssertionError: False is not true

======================================================================
FAIL: test_validates_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-1mbn8id/test.py", line 197, in test_validates_numbers
    self.assertTrue(solution.Validations.is_number('9'))
AssertionError: False is not true

----------------------------------------------------------------------
Ran 39 tests in 0.062s

FAILED (failures=16)

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

Емилиан обнови решението на 17.04.2014 21:54 (преди над 10 години)

+import re
+
+
+class Validations():
+ def is_email(value):
+ host = r'([^\W_][a-zA-Z0-9-]{,62}[a-zA-Z0-9][.])+[a-zA-Z]{2,3}'
+ pattern = r'^[^\W_][\w+-.]{,200}@%s$' % host
+ return bool(re.search(pattern, value))
+
+ def is_hostname(value):
+ pattern = r'^([^\W_][a-zA-Z0-9-]{,62}[a-zA-Z0-9][.])+[a-zA-Z]{2,3}$'
+ return bool(re.search(pattern, value))
+
+ def is_phone(value):
+ pattern = r'^([0]|(\+|00)[1-9]{1,3})[ ()-]?[1-9]([ ()-]?[0-9]){5,10}$'
+ return bool(re.search(pattern, value))
+
+ def is_ip_address(value):
+ valid_number = r'(0|[1-9][0-9]|[1-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])'
+ pattern = r'^(%s.){3}%s$' % (valid_number, valid_number)
+ return bool(re.search(pattern, value))
+
+ def is_number(value):
+ pattern = r'^0$|^-?(0|[1-9][0-9]+)[.][0-9]+$|^-?[1-9][0-9]+$'
+ return bool(re.search(pattern, value))
+
+ def is_integer(value):
+ pattern = r'^0$|^-?[1-9][0-9]+$'
+ return bool(re.search(pattern, value))
+
+ def is_date(value):
+ pattern = r'^[0-9]{4}-(0[1-9]|1[0-2])-([0-2][0-9]|3[01])$'
+ return bool(re.search(pattern, value))
+
+ def is_time(value):
+ pattern = r'^([0-1][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]$'
+ return bool(re.search(pattern, value))
+
+ def is_datetime(value):
+ date = r'[0-9]{4}-(0[1-9]|1[0-2])-([0-2][0-9]|3[01])'
+ time = r'([0-1][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]'
+ pattern = r'^%s[ T]%s$' % (date, time)
+ return bool(re.search(pattern, value))
+
+
+class PrivacyFilter():
+ def __init__(self, text):
+ self.text = text
+ self.preserve_phone_country_code = False
+ self.preserve_email_hostname = False
+ self.partially_preserve_email_username = False
+ #^^^^^^^^^^^^MUST.MAKE.THESE.FLAGS.WORK.^^^^^^^^^^^^^
+
+ def filtered(self):
+ filtered = self.text
+ phone = r'([0]|(\+|00)[1-9]{1,3})[ ()-]?[1-9]([ ()-]?[0-9]){5,10}'
+ host = r'([^\W_][a-zA-Z0-9-]{,62}[a-zA-Z0-9][.])+[a-zA-Z]{2,3}'
+ email = r'[^\W_][\w+-.]{,200}@%s' % host
+ filtered = re.sub(phone, '[PHONE]', filtered)
+ filtered = re.sub(email, '[EMAIL]', filtered)
+ return filtered

Емилиан обнови решението на 18.04.2014 14:39 (преди над 10 години)

import re
class Validations():
- def is_email(value):
+ @classmethod
+ def is_email(self, value):
host = r'([^\W_][a-zA-Z0-9-]{,62}[a-zA-Z0-9][.])+[a-zA-Z]{2,3}'
pattern = r'^[^\W_][\w+-.]{,200}@%s$' % host
return bool(re.search(pattern, value))
- def is_hostname(value):
+ @classmethod
+ def is_hostname(self, value):
pattern = r'^([^\W_][a-zA-Z0-9-]{,62}[a-zA-Z0-9][.])+[a-zA-Z]{2,3}$'
return bool(re.search(pattern, value))
- def is_phone(value):
+ @classmethod
+ def is_phone(self, value):
pattern = r'^([0]|(\+|00)[1-9]{1,3})[ ()-]?[1-9]([ ()-]?[0-9]){5,10}$'
return bool(re.search(pattern, value))
- def is_ip_address(value):
+ @classmethod
+ def is_ip_address(self, value):
valid_number = r'(0|[1-9][0-9]|[1-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])'
pattern = r'^(%s.){3}%s$' % (valid_number, valid_number)
return bool(re.search(pattern, value))
- def is_number(value):
+ @classmethod
+ def is_number(self, value):
pattern = r'^0$|^-?(0|[1-9][0-9]+)[.][0-9]+$|^-?[1-9][0-9]+$'
return bool(re.search(pattern, value))
- def is_integer(value):
+ @classmethod
+ def is_integer(self, value):
pattern = r'^0$|^-?[1-9][0-9]+$'
return bool(re.search(pattern, value))
- def is_date(value):
+ @classmethod
+ def is_date(self, value):
pattern = r'^[0-9]{4}-(0[1-9]|1[0-2])-([0-2][0-9]|3[01])$'
return bool(re.search(pattern, value))
- def is_time(value):
+ @classmethod
+ def is_time(self, value):
pattern = r'^([0-1][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]$'
return bool(re.search(pattern, value))
- def is_datetime(value):
+ @classmethod
+ def is_datetime(self, value):
date = r'[0-9]{4}-(0[1-9]|1[0-2])-([0-2][0-9]|3[01])'
time = r'([0-1][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]'
pattern = r'^%s[ T]%s$' % (date, time)
return bool(re.search(pattern, value))
class PrivacyFilter():
def __init__(self, text):
self.text = text
self.preserve_phone_country_code = False
self.preserve_email_hostname = False
self.partially_preserve_email_username = False
#^^^^^^^^^^^^MUST.MAKE.THESE.FLAGS.WORK.^^^^^^^^^^^^^
def filtered(self):
filtered = self.text
- phone = r'([0]|(\+|00)[1-9]{1,3})[ ()-]?[1-9]([ ()-]?[0-9]){5,10}'
+ phone = r'(\b|\s)([0]|(\+|00)[1-9]{1,3})' \
+ r'[ ()-]?[1-9]([ ()-]?[0-9]){5,10}'
host = r'([^\W_][a-zA-Z0-9-]{,62}[a-zA-Z0-9][.])+[a-zA-Z]{2,3}'
- email = r'[^\W_][\w+-.]{,200}@%s' % host
- filtered = re.sub(phone, '[PHONE]', filtered)
+ email = r'[^\W_][\w+-.]{,200}(@%s)' % host
+ if self.preserve_phone_country_code:
+ filtered = re.sub(phone, r'\1\2%s' % ' [FILTERED]', filtered)
+ if self.preserve_email_hostname:
+ filtered = re.sub(email, r'%s\1' % '[FILTERED]', filtered)
+ if self.partially_preserve_email_username:
+ partial_email = r'([^\W_][\w+-.]{2})[\w+-.]{,197}(@%s)' % host
+ filtered = re.sub(partial_email,
+ r'\1%s\2' % '[FILTERED]', filtered)
+ filtered = re.sub(phone, r'\1%s' % '[PHONE]', filtered)
filtered = re.sub(email, '[EMAIL]', filtered)
return filtered

Емилиан обнови решението на 18.04.2014 20:23 (преди над 10 години)

import re
class Validations():
@classmethod
def is_email(self, value):
host = r'([^\W_][a-zA-Z0-9-]{,62}[a-zA-Z0-9][.])+[a-zA-Z]{2,3}'
pattern = r'^[^\W_][\w+-.]{,200}@%s$' % host
return bool(re.search(pattern, value))
@classmethod
def is_hostname(self, value):
pattern = r'^([^\W_][a-zA-Z0-9-]{,62}[a-zA-Z0-9][.])+[a-zA-Z]{2,3}$'
return bool(re.search(pattern, value))
@classmethod
def is_phone(self, value):
pattern = r'^([0]|(\+|00)[1-9]{1,3})[ ()-]?[1-9]([ ()-]?[0-9]){5,10}$'
return bool(re.search(pattern, value))
@classmethod
def is_ip_address(self, value):
valid_number = r'(0|[1-9][0-9]|[1-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])'
pattern = r'^(%s.){3}%s$' % (valid_number, valid_number)
return bool(re.search(pattern, value))
@classmethod
def is_number(self, value):
- pattern = r'^0$|^-?(0|[1-9][0-9]+)[.][0-9]+$|^-?[1-9][0-9]+$'
+ pattern = r'^-?0$|^-?(0|[1-9][0-9]+)[.][0-9]+$|^-?[1-9][0-9]+$'
return bool(re.search(pattern, value))
@classmethod
def is_integer(self, value):
- pattern = r'^0$|^-?[1-9][0-9]+$'
+ pattern = r'^-?0$|^-?[1-9][0-9]+$'
return bool(re.search(pattern, value))
@classmethod
def is_date(self, value):
- pattern = r'^[0-9]{4}-(0[1-9]|1[0-2])-([0-2][0-9]|3[01])$'
+ pattern = r'^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$'
return bool(re.search(pattern, value))
@classmethod
def is_time(self, value):
pattern = r'^([0-1][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]$'
return bool(re.search(pattern, value))
@classmethod
def is_datetime(self, value):
date = r'[0-9]{4}-(0[1-9]|1[0-2])-([0-2][0-9]|3[01])'
time = r'([0-1][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]'
pattern = r'^%s[ T]%s$' % (date, time)
return bool(re.search(pattern, value))
class PrivacyFilter():
def __init__(self, text):
self.text = text
self.preserve_phone_country_code = False
self.preserve_email_hostname = False
self.partially_preserve_email_username = False
- #^^^^^^^^^^^^MUST.MAKE.THESE.FLAGS.WORK.^^^^^^^^^^^^^
def filtered(self):
filtered = self.text
phone = r'(\b|\s)([0]|(\+|00)[1-9]{1,3})' \
r'[ ()-]?[1-9]([ ()-]?[0-9]){5,10}'
host = r'([^\W_][a-zA-Z0-9-]{,62}[a-zA-Z0-9][.])+[a-zA-Z]{2,3}'
email = r'[^\W_][\w+-.]{,200}(@%s)' % host
if self.preserve_phone_country_code:
filtered = re.sub(phone, r'\1\2%s' % ' [FILTERED]', filtered)
if self.preserve_email_hostname:
filtered = re.sub(email, r'%s\1' % '[FILTERED]', filtered)
if self.partially_preserve_email_username:
partial_email = r'([^\W_][\w+-.]{2})[\w+-.]{,197}(@%s)' % host
filtered = re.sub(partial_email,
r'\1%s\2' % '[FILTERED]', filtered)
filtered = re.sub(phone, r'\1%s' % '[PHONE]', filtered)
filtered = re.sub(email, '[EMAIL]', filtered)
return filtered