regex - 正则表达式匹配接下来的 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 个单词。
上面的正则表达式似乎不起作用 - 关于修复什么的任何想法?
解决方案
试试这个模式Paragraph ([\w()]+ ?\n?){1,6}
。
[\w()]+
- 匹配任何单词字符或(
一次)
或多次,
?\n?
- 最多匹配一次空格和换行(单独),
{1,6}
- 匹配组至少一个,最多6次,你最多要5个单词,但我也在数13
和3(b)
。
推荐阅读
- amazon-web-services - 私有子网未与公共通信 - 健康检查失败
- reactjs - 如何在不使用redux的情况下刷新访问令牌
- reactjs - 单击链接时第二次未在图表中显示数据
- unity3d - 使用 Unity 标准透明着色器的模型相互重叠
- reactjs - 无缝不可变地将我的对象转换为哈希
- symfony - Bootstrap 正确导入但样式不起作用
- php - 在php中获取并显示mysql中相同类型的所有值
- spring-boot - STS 中 Maven 项目的打包问题
- arrays - 制作二进制到十进制转换器,但需要将char数组转换为整数数组
- xamarin - Xamarin iOS 库无法获取位置