Я пытаюсь найти биржевые тикеры в файлах PDF с помощью 1) использования регулярных выражений для поиска в документе всего, что похоже на биржевую бирку, а затем 2) сравнения его с существующим списком известных тикеров.У меня нет проблем с № 1, но это приводит к некоторым ложным срабатываниям.
Так как мне сделать так, чтобы совпадение было только в том случае, если оно найдено в существующем списке?Вот мой код:
tickers = ['CA', 'V', 'MA', 'EB', 'PE', 'QCOM', 'BAC', 'A', 'AMZN']
text = 'This is sample text that mentions different companies and tickers like
V (Visa), QCOM (Qualcomm), A (Agilent), GE (General Electric), MA (Mastercard),
EB (Eventbrite), and PE (Parsley Energy Inc). The output should ignore values
that do not match regex AND do not appear in the tickers list. For example,
GXXX, ALLL, and QQWE should not match since they do not appear in the
tickers list.'
regex = re.compile(r'\b[A-Z]{1,5}\b[.!?]?')
matches = regex.finditer(text)
for match in matches:
print(match)