redact_numerics_1.py 461 B

12345678
  1. def sensitive_numerics(number):
  2. number = re.sub(r'[\+\(]?\d[\d .\-\(\)]{6,}', r'xxx', number)
  3. # [0-9] matches a single digit in the range 0 through 9 (inclusive), {4} indicates that four such digits should occur in a row,
  4. # - means a hyphen, and | means an OR and separates the two patterns you mention.
  5. # '123-4-5648' '1-234-5-6789'
  6. number = re.sub('[0-9]-[0-9]{3}-[0-9]-[0-9]{4}|[0-9]{3}-[0-9]-[0-9]{4}', 'xxx', number)
  7. return number