【问题标题】:Python Regular Expression getting sub string [closed]Python正则表达式获取子字符串[关闭]
【发布时间】:2020-05-13 13:07:59
【问题描述】:

card_travel2 - 3 yrslocation_onKolkata

从上面的字符串中我想得到 2 - 3 yrs 我可以使用哪个正则表达式?

【问题讨论】:

  • 请清楚描述您的问题。

标签: python regex


【解决方案1】:

希望你看起来像这样,

import re
pattern = r'\d+\s+-\s+\d+\s+yrs'
text = 'card_travel2 - 3 yrslocation_onKolkata'
re.findall(pattern, text)

输出

['2 - 3 yrs']

【讨论】:

  • ['2 - 3 yrs'] 你能告诉我如何删除括号和引号吗?我只需要 2 - 3 年..
  • re.findall(pattern, text)[0]
  • 非常感谢,现在这个字符串中的最后一个 Aryan 技术(更多工作)我只想要组织名称。表示我想删除(更多工作)部分。
  • 只需使用字符串替换的方法,例如:inp_str.replace('(more jobs)','')
  • 不工作..它给了我相同的字符串
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-07-31
  • 1970-01-01
  • 2021-12-30
  • 1970-01-01
  • 2017-06-07
  • 2014-01-20
相关资源
最近更新 更多