fork download
  1. import re
  2.  
  3. regex = r"\b(?:\d{6} \d{5}|[1-9]\d{4} \d{5}|[1-9]\d{9}|\d{11})\b"
  4.  
  5. test_str = ("Pattern 1 - The length of this pattern is exactly 10 and cannot start with a zero. These consist of only integers. Ex: '1234567890'\n\n"
  6. "Pattern 2 - The length of this pattern is exactly 11 and can start with a zero. These consist of only integers. Ex: '01234567890'\n\n"
  7. "Pattern 3 - The length of this pattern is exactly 11 and cannot start with a zero. There is one space after the 5th number and all other characters are numbers. Ex: '12345 67890'\n\n"
  8. "Pattern 4 - The length of this pattern is exactly 12 and can start with a zero. There is one space after the 6th number and all other characters are numbers. Ex: '012345 67890'\n\n"
  9. "Test 0000000000\n"
  10. "Test 123456789011\n"
  11. "Test 02345 66666")
  12.  
  13. print(re.findall(regex, test_str))
Success #stdin #stdout 0.02s 9620KB
stdin
Standard input is empty
stdout
['1234567890', '01234567890', '12345 67890', '012345 67890']