【问题标题】:How do I remove all questions from a text with regex and stringr?如何使用 regex 和 stringr 从文本中删除所有问题?
【发布时间】:2021-12-18 16:26:06
【问题描述】:

编辑以证明我自己努力解决了这个问题

我有以下字符串:

"This is a question? This is an answer This is another question? This is another answer."

我想做的是创建一个匹配所有问题的正则表达式,以便我可以删除它们。在这种情况下,前面的答案或句子并不总是以“。”结尾。 (句号)。所以我正在寻找的是匹配以问号结尾并以大写字母开头的句子。

我要匹配的内容:

"This is a question?" and "This is another question?"

我在 R 中工作,所以我更喜欢使用 stringr 的答案,但我最感兴趣的是我应该应用的正则表达式。

我尝试了以下正则表达式^[A-Z].+\?,但不幸的是它与整个字符串匹配。

【问题讨论】:

标签: r regex stringr


【解决方案1】:

这应该在正则表达式中起作用:([A-Z][^A-Z?]*\?)

【讨论】:

    猜你喜欢
    • 2019-02-28
    • 2019-08-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多