Regular expression

I'm having problems matching stock quotes in a line of text. I want the regular expression to match a space, 3 uppercase letters, and finally a space, period or question mark.

Below is a sample template that I created.

> `example = 'These are the tickers that I am trying to find: FAB. APL APL? GJA ADJ AKE EBY ZKE SPR TYL'

re.findall('[ ][A-Z]{3}[ .!?]',example)`

The regular expression skips a lot of matches.

+4
source share
2 answers

If you notice, there is a pattern by which elements are skipped. This is most evident in a long section of characters without an accent: it skips every other element.

, re.findall() , , . , .

(\b) / :

>>> re.findall(r'\b[A-Z]{3}\b[.!?]?',example)
['FAB.', 'APL', 'APL?', 'GJA', 'ADJ', 'AKE', 'EBY', 'ZKE', 'SPR', 'TYL']
+6

\s[A-Z]{3}[\s\.\?] ( "!" , )

-1

Source: https://habr.com/ru/post/1691511/


All Articles