【问题标题】:Extracting text in between certain text/tags in python在python中的某些文本/标签之间提取文本
【发布时间】:2022-01-19 19:53:27
【问题描述】:

假设我有一段文字: 注意:这是我正在阅读的文件,因此实际上并没有在代码中注释掉它

" ## 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]## "

我想提取方括号之前的元素,例如,在这段文字中我想:客户服务[-3]和技术服务[-3]

有什么很酷的方法可以做到这一点(使用一些正则表达式的应用程序),因为我现在很难过。

【问题讨论】:

  • 方括号中提到的数字的可能值是什么?

标签: python string nlp


【解决方案1】:

以正则表达式的方式寻址。

演示:https://regex101.com/r/mWsAHf/1

模式:\w+ \w+\[-?\d+]

【讨论】:

  • 如果我只想要每个方括号内的数字呢
  • 集团声明将在这里为您提供帮助。演示:regex101.com/r/DhjZ3F/1
猜你喜欢
  • 1970-01-01
  • 2020-03-17
  • 2014-08-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-10-21
相关资源
最近更新 更多