首页 > 解决方案 > 正则表达式匹配接下来的 1 到 3 个单词和之后的任何内容

问题描述

我的正则表达式是:

Paragraph 1[34]{1}(\w+\s?){1,5}[\s\S]*?\WReturn Amount\W\shas the meaning specified in\s(Paragraph \S+)\sof this Annex

我的字符串是:

Paragraph 13 Elections Variables something
next line something else "Return Amount" has the meaning specified in Paragraph 3(b) of this Annex.

我期待一个名为第 13 段选举变量的小组和一个小组第 3(b) 段第一组可以有 1 到 5 个单词。

上面的正则表达式似乎不起作用 - 关于修复什么的任何想法?

标签: regex

解决方案


试试这个模式Paragraph ([\w()]+ ?\n?){1,6}

[\w()]+- 匹配任何单词字符或(一次)或多次,

?\n?- 最多匹配一次空格和换行(单独),

{1,6}- 匹配组至少一个,最多6次,你最多要5个单词,但我也在数133(b)

演示


推荐阅读