在 python 中的某些 text/tags 之间提取文本
Extracting text in between certain text/tags in python
假设我有一段文字:
注意:这是我正在阅读的文件,因此它实际上并没有在代码中被注释掉
" ## 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 for a warrantied iPod.
technical service[-3]## "
并且我想提取方括号之前的元素,例如,在这段文字中我想:CUSTOMER SERVICE[-3] and technical service[-3]
有什么好的方法可以做到这一点(使用 Regex 的某些应用程序),因为我现在很困惑。
以正则表达式方式寻址。
演示:https://regex101.com/r/mWsAHf/1
模式:\w+ \w+\[-?\d+]
假设我有一段文字: 注意:这是我正在阅读的文件,因此它实际上并没有在代码中被注释掉
" ## 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 for a warrantied iPod.
technical service[-3]## "
并且我想提取方括号之前的元素,例如,在这段文字中我想:CUSTOMER SERVICE[-3] and technical service[-3]
有什么好的方法可以做到这一点(使用 Regex 的某些应用程序),因为我现在很困惑。
以正则表达式方式寻址。
演示:https://regex101.com/r/mWsAHf/1
模式:\w+ \w+\[-?\d+]