0

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.

1
  • what are the possible values for number mentioned under square bracket? Commented Dec 16, 2021 at 18:27

1 Answer 1

1

Addressed in regex way.

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

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

Sign up to request clarification or add additional context in comments.

2 Comments

what about If i just want the numbers inside each of the square brackets
Group statement will help you here. Demo: regex101.com/r/DhjZ3F/1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.