简体   繁体   中英

How to select a string of variable length but with fixed beginning and ending?

I have many strings like statt 29,95 € nur 26,95€8) statt 39,95 € nur 35,95€13) I want to select & remove part which is coming between statt 29,95 € nur .

String will always start with statt and end with nur and wil contain some variable length price value in between them. I want them to be removed from my data and contain price values coming after nur only.

I looked into the possibility of regex but could not devise a method to use it in my case. Please help me in resolving this issue and pardon my ignorance as I am new to programming.

If you want to remove all occurences of

"statt 29,95 € nur "

with different prices in "€,cents", you can use this regex:

text = re.sub(r'statt \d+,\d+ € nur ', '', text)

Also, check your encoding, since the characters after the price do not appear naturally.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM