Я проверил свой код, чтобы убедиться, что мой шаблон соответствует тестовому примеру test
, но по какой-то причине он не находит совпадений в текстовой строке text_to_search
. Может кто-нибудь помочь мне здесь? Сначала я подумал, что исправил это, потому что я забыл об использовании .group(0)
для печати полного соответствия, но он все еще не работает.
Вот мой код:
test = 'E000.1'
text_to_search = '''
237.0-237.2 is the range for the ICD-9 codes for neoplasm of uncertain behavior of\
endocrine glands and nervous system. On the hand, the ICD-9 code for Type II Diabetes\
with other manifestations is 250.8x where x is 0 or 2 depending on controlled or\
uncontrolled.
'''
pattern = re.compile(r'^(V\d{2}(\.\w{1,3})?|\d{3}(\.\w{1,2})?|E\d{3}(\.\w{1,2})?)-?(V\d{2}(\.\w{1,3})?|\d{3}(\.\w{1,2})?|E\d{3}(\.\w{1,2})?)?$')
matches = pattern.finditer(text_to_search)
for match in matches:
print(matches.group(0))