【问题标题】:How to find a group of consecutive leters and check cases with python re如何使用python re找到一组连续的字母并检查大小写
【发布时间】:2014-03-07 01:06:04
【问题描述】:

我如何执行re.findall() 来查找一组 7 个字母,其中前 3 个和后 3 个都是大写字母,而中间的字母是小写字母?到目前为止,我已经尝试过:

word1 = "".join(re.findall("[A-Z][A-Z][A-Z][a-z][A-Z][A-Z][A-Z]\d{3}","mystring")]

但是,它不输出任何东西。

我该如何做这个查询?

谢谢!

伊夫维德

【问题讨论】:

  • print word1 显示什么?
  • 您的正则表达式显然与“mystring”不匹配。你试过有效输入吗?
  • @diveshpremdeep 我确实在有效输入上试过了——但是说有效输入太长了,不能放在这里。

标签: python regex python-2.7 uppercase


【解决方案1】:

嗯,这对我有用

p = re.compile(r"[A-Z]{3}[a-z][A-Z]{3}")

word = "".join(re.findall(p, 'udkehtEOajidfEEfjaiERBdEHY alijdfilaOEPvOEG'))

输出:

>>> print word
'ERBdEHYOEPvOEG'

当然,如果你真的在"mystring" 中搜索,你自然会找不到匹配项。

【讨论】:

    猜你喜欢
    • 2023-03-25
    • 2011-11-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-23
    • 1970-01-01
    • 2018-07-13
    • 2014-11-28
    • 1970-01-01
    相关资源
    最近更新 更多