Regular expression for stock tickers – Python

We Are Going To Discuss About Regular expression for stock tickers – Python. So lets Start this Article.

Regular expression for stock tickers – Python

How to solvwe Regular expression for stock tickers – Python

Match the dollar sign, one letter, and then anything that’s not a space:
re.findall(r'[$][A-Za-z][\S]*', str(i))

Regular expression for stock tickers – Python

Match the dollar sign, one letter, and then anything that’s not a space:
re.findall(r'[$][A-Za-z][\S]*', str(i))

Solution 1

Match the dollar sign, one letter, and then anything that’s not a space:

re.findall(r'[$][A-Za-z][\S]*', str(i))

Original Author Harald Nordgren Of This Content

Solution 2

The package reticker does this by creating a custom regular expression as per its configuration. It uses the created pattern to extract tickers from text. Alternatively, the returned pattern can be used independently.

>>> import reticker

>>> extractor = reticker.TickerExtractor()
>>> type(extractor.pattern)
<class 're.Pattern'>

>>> extractor.extract("Comparing FNGU vs $WEBL vs SOXL- who wins? And what about $cldl vs $Skyu? IMHO, SOXL is king!\nBTW, will the $w+$Z pair still grow?")
['FNGU', 'WEBL', 'SOXL', 'CLDL', 'SKYU', 'W', 'Z']

>>> extractor.extract("Which of BTC-USD, $ETH-USD and $ada-usd is best?\nWhat about $Brk.a and $Brk.B? Compare futures MGC=F and SIL=F.")
['BTC-USD', 'ETH-USD', 'ADA-USD', 'BRK.A', 'BRK.B', 'MGC=F', 'SIL=F']

Original Author Asclepius Of This Content

Solution 3

I’ll just leave this here for people looking for a regex that matches a stock ticker

re.fullmatch('([A-Za-z]{1,5})(-[A-Za-z]{1,2})?', symbol)

Original Author Tom Sawyer Of This Content

Conclusion

So This is all About This Tutorial. Hope This Tutorial Helped You. Thank You.

Also Read,

ittutorial team

I am an Information Technology Engineer. I have Completed my MCA And I have 4 Year Plus Experience, I am a web developer with knowledge of multiple back-end platforms Like PHP, Node.js, Python and frontend JavaScript frameworks Like Angular, React, and Vue.

Leave a Comment