【问题标题】:Extracting the exact word between two words without question mark in python using REGEX使用REGEX在python中提取两个没有问号的单词之间的确切单词
【发布时间】:2021-08-03 16:55:49
【问题描述】:

我正在尝试在字符串中的两个特定单词之间提取一个单词。

这是我迄今为止尝试过的,

import re
st = 'did this something?Yessomething'
re.findall('did this something?(.*?)something', st)
Current Output: ['?Yes']
Desired Output: ['Yes']

我可以用空格替换问号以获得所需的输出,但我正在寻找在问号和下一个单词之后提取确切单词的方法。

【问题讨论】:

    标签: python python-3.x regex


    【解决方案1】:

    你需要在something之后转义?

    按如下方式进行:

    print(re.findall('did this something\\?(.*?)something', st))
    

    输出:

    ['Yes']
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-12-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-30
      • 2012-04-13
      • 1970-01-01
      • 2022-01-12
      相关资源
      最近更新 更多