What regular expression should I use to extract stock symbols from text file?

Advertisements I would like to extract all the symbols from a text file with a regular expression, ALLY, AMZN, AXP, AON, etc… The following data is in a text file Symbol Holdings Stake Mkt. price Value Pct of portfolio Ally Financial Inc ALLY 29,000,000 9.6% $25.59 $742,110,000 0.2% Amazon.com, Inc. AMZN 10,551,000 0.1% $137.09 $1,446,436,590… Read More What regular expression should I use to extract stock symbols from text file?

How to Extract Full Sentence from Text Including Newline(s) Using Python?

Advertisements I am trying to get text from PDF file. However, I cannot get the entire sentence that I want. I think below example clearly explains my problem. Text I want to take: Start Date: 01/01/2023 Name Surname: 123456789 Fernando Alonso Salary: 1.915,15$ Address: SPAIN, MADRID, 12345, FORMULA, RENAULT BLV. ASTON MARTIN STREET\n – A5… Read More How to Extract Full Sentence from Text Including Newline(s) Using Python?

Filtering a string in regex

Advertisements I am trying to use regex for the first time because I have a very large text file (over 2000 lines) that contains some data I need to parse and correct. Consider the following: |C170|14|1712||5,00000|UN|3,05|0,00|0|000|5102|1100|3,05|| |C170|15|1713||5,00000|UN|2,50|0,00|0|000|5102|1100|2,50|| |C100|1|0|000009043|55|00|1|12769|52230734631526000191550010000127691220214465|03072023| |C170|1|2005||1,00000|UN|395,00|0,00|0|000|5102|1100|395,00|| |C100|1|0|000009316|55|00|1|12770|52230734631526000191550010000127701782306100|03072023| |C170|1|119||1,00000|UN|245,00|0,00|0|000|6102|1100|245,00|| |C170|2|5651||1,00000|PC|299,00|0,00|0|000|6102|1100|299,00|| |C170|3|211||2,00000|UN|10,00|0,00|0|000|6102|1100|10,00|12,00|| I need to filter every line that starts with |C170|. Sometimes that… Read More Filtering a string in regex

extract and count lists from text file in python

Advertisements I have a large text file that includes so many lists. Each list includes random numbers as follows. Test file: [-1460,-1460,-1460,-1460,-1460,0,-1460,0,-1460,-1460,-1460,45,-1460,-1460,-1460,-1460,-1460,-1460] [250,-1250,36,-1250,-1250,33,-1250,-1250,-1250,-1250,-1250,-1250,-1250,-490,-1243,-1250,-1250,-1250,-1250,-1250,33,-1250,33,-1250,-1250,-1250,-1250,-1250,-1250,33,-496,-1243,-1250,33,-1250,-1246,-1250,-1250,-1250,-1250,35,-1250,-1250,33,-1250,-1250,-1250,-1250,-1250,-1250,-1250,-1250,33,-1250,-1250,-1250,-1250,-525,-1250,33,-259,-1250] [2,-1232,34,34,34,0,0,-1232,-1232,-1232,-1232,34,34,-1232,-1232,-1232,-1232,-1232,-1232,-1232,-1232,34,34,-1232,34,-1232,34,34,-1232,-1232,-1232,39,-1232,34,-1232,-1232,-1232,34,-1232,0,0,34,-1232,-1232,-1232,-1232,-1232,517,0,34,34,34,-1232,-1232,-1232,-1232,-1232,-1232,34,-1232,-1232,-1232,34,-1232,34,-1232,34,-1232,34] …… First, I want to count how many lists are there in the text file. Then, I want to extract every list separately for further processing. I created a code to… Read More extract and count lists from text file in python

How to build relevant auto generating tags recommendation model in python

Advertisements How to Build a Relevant Auto Generating Tags Recommendation Model in Python One of the most important features of any blog or website is its ability to recommend relevant tags to users. This not only helps users find related content easily, but it also improves the overall user experience. In this blog post, we’ll… Read More How to build relevant auto generating tags recommendation model in python

How to return a sentence with an exact word not as a part of the other word

Advertisements I need to find all sentences with exact word match. Not inside of the other words. I’m trying this: text=’He’s using apple phone. I like apples. Did you install this app? Apply today!’ [sentence + ‘.’ for sentence in text.split(‘.’) if ‘app’ in sentence] I get the output: ‘He’s using apple phone. I like… Read More How to return a sentence with an exact word not as a part of the other word