【问题标题】:How to find a string that follows after the first "of" of a range如何查找范围的第一个“of”之后的字符串
【发布时间】:2022-07-07 23:27:36
【问题描述】:

我有以下字符串

... of 7th July 2019 , signed by the District Director of the National Service of ENCAC.

我想找到

the National Service of ENCAC

我有这个正则表达式可以从 "signed by" 中搜索,但我希望它从 "signed by" 后面的第一个 "of" 中搜索

(?<=signed by)(.*)(?=\.)

非常感谢您的帮助。

【问题讨论】:

  • 您可以使用\bsigned\s+by\b.*?\bof\s([^.]+) (demo)。或者,\bsigned\s+by\b.*?\bof\s\K[^.]+ (demo)

标签: regex


【解决方案1】:

您可以匹配直到of签名 之后第一次出现,而不是向后看,然后使用捕获组并匹配尾随点。

\bsigned by\b.*?\bof\b\s*([^.]*)\.

Regex demo

如果中间也不能有点:

\bsigned by\b[^.]*?\bof\b\s*([^.]*)\.

Regex demo

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-06-04
    • 1970-01-01
    • 2011-11-05
    • 1970-01-01
    • 2018-01-19
    • 2011-11-20
    • 1970-01-01
    相关资源
    最近更新 更多