Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Extracting text in between certain text/tags in python

So let’s say I have a piece of text:
Note: this is a file I’m reading in so it isn’t actually commented out in the code

" ## BATTERY LIFE: Pretty medicore at 12 hours, the Creative, iAudio, Rio, and iRiver players last longer. 
CUSTOMER SERVICE[-3]## CUSTOMER SERVICE: Awful. Listen to this one, remember the battery statement I made earlier. 
##If your battery dies and it's still under warranty, guess what, you're out of luck, because Apple doesn't cover the battery in the iPod warranty. 
##They have the nerve to charge you $30 for a warrantied iPod.
technical service[-3]## "

And I want to extract the elements just before the square brackets, for example, in this piece of text I would like: CUSTOMER SERVICE[-3] and technical service[-3]

Is there any cool way to got about doing this (using some application of Regex) because I’m stumped at the moment.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Addressed in regex way.

Demo: https://regex101.com/r/mWsAHf/1

Pattern: \w+ \w+\[-?\d+]

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading