0

I have a requirement to find specific numbers in text however I'm getting false positives on substrings.

import re

test_string = """ <419501> :422675: 419508 adsfasdf11412129 """


regex_pattern = re.compile(r'(419501|422675|419508|412129)(\b|$)', re.I)

matches =  re.findall(regex_pattern, test_string)
print matches

this works well in some cases however it gives me a false positive for this string:

  adsfasdf11412129

Any instance of the number surrounded by white space, newlines, or special characters will be a valid hit. Any leading characters or numbers is a false positive. Any suggestions?

Chris Hall
  • 871
  • 6
  • 13
  • 21

0 Answers0