提问人:john 提问时间:10/22/2023 更新时间:10/22/2023 访问量:66
正则表达式:对以给定字符开头的所有字符串块进行分组
Regex: Group all blocks of strings starting with a given character
问:
我在 javascript 中有一个这样的文本
some text
- list
- list
- list
more text
- another list
- another list
- another list
如何匹配所有以该字符开头的行,直到一行不以该字符开头?
例如,根据上面的文本,我需要匹配两个组-
- list
- list
- list
和
- another list
- another list
- another list
我尝试使用正则表达式,但仅当列表包含偶数个元素时才有效,而我需要它才能适用于任意数量的元素。/^(-.*\n-.*|$)/gm
答:
下一个:根据特定模式对标签进行分组
评论
^-.*(?:\n-.*)*