【问题标题】:regular expression not matching multi line string [duplicate]正则表达式不匹配多行字符串[重复]
【发布时间】:2021-04-11 22:09:57
【问题描述】:

例句是:

"Thanks to this crisis, there has been a wake-up call to some of these neobanks," said Ali Niknam, CEO and founder of Dutch online 
bank Bunq. "To run a healthy business, you need healthy business conduct."

我的正则表达式是

(said)\s.*,\s(CEO and founder of)\s.*\.

我希望它匹配到

said Ali Niknam, CEO and founder of Dutch online 
bank Bunq.

但不是因为在线字后的break。有没有办法在不修改示例文本的情况下使其工作?

【问题讨论】:

  • 检查已编辑的句子。所以以某种方式吃了它的方式
  • 好的试试这个:said\s[\s\S]*?,\sCEO and founder of\s[\s\S]*?\.

标签: regex typescript


【解决方案1】:

请看这里:https://regexr.com/5jms2。

  1. . 不包括换行符。您可以改用(.|\n)。
  2. * 默认是贪婪的。使用*? 使其不贪婪,即它匹配最少数量的文本,直到匹配下一个表达式(在本例中为\.)。

【讨论】:

  • 抱歉,这不正确。我的问题不同。就我而言,它根本不匹配任何东西。
  • 那么您的帖子中输入的文字可能不正确。请检查一下。
  • 请看。
猜你喜欢
  • 2020-06-03
  • 1970-01-01
  • 1970-01-01
  • 2023-03-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多