[英]Regex matching multiple lines in one match group
I've got the following string:我有以下字符串:
<div>Some headline - list 1<br />
> List item 1<br />
> List item 2<br />
> List item 3<br />
<br />
List 2<br />
> foo<br />
> bar<br />
> baz<br />
<br />
</div>
It contains two maleformed lists.它包含两个畸形列表。 It is my goal to wrap the items of these lists into
<ul>
.我的目标是将这些列表的项目包装到
<ul>
。 To accomplish that, I am looking for a regex that matches all Items of each list into one match group.为了实现这一点,我正在寻找一个将每个列表的所有项目匹配到一个匹配组的正则表达式。
So my expected result would be:所以我的预期结果是:
> List item 1<br />
> List item 2<br />
> List item 3<br />
and和
> foo<br />
> bar<br />
> baz<br />
All regex magic I tired failed because they did match only a single line of the list, or the match group was including all the content between the beginning of the first list and the end of the last one.我厌倦的所有正则表达式魔术都失败了,因为它们只匹配了列表的一行,或者匹配组包含了第一个列表的开头和最后一个列表的结尾之间的所有内容。
I've tried ~> (.*)<br />\\s~gis
我试过了
~> (.*)<br />\\s~gis
~> (.*)<br />\\s~gis
which matches both of the lists. ~> (.*)<br />\\s~gis
匹配两个列表。
You can try this regex, To capture only the Lists.,你可以试试这个正则表达式,只捕获列表。,
Im using java regex.,我使用java正则表达式。,
(> .*(?:<br\s/>\s+List\s2<br\s/>)?)
It captures these elements.,它捕获了这些元素。,
> List item 1<br />
> List item 2<br />
> List item 3<br />
> foo<br />
> bar<br />
> baz<br />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.