2

I'm sure this question has been asked before, but I'm unable to find it.

I have a bunch of list elements like so:

<li class="list-item">aewfaffjpiowfj: apeifjeawpfioj</li>
<li class="list-item">aewfaffjpiowfj: apeifjeawpfioj</li>
<li class="list-item">aewfaffjpiowfj: apeifjeawpfioj</li>
<li class="list-item">aewfaffjpiowfj: apeifjeawpfioj</li>
<br><br>

sample text
<li class="list-item">aewfaffjpiowfj: apeifjeawpfioj</li>
<li class="list-item">aewfaffjpiowfj: apeifjeawpfioj</li>

more text
<li class="list-item">aewfaffjpiowfj: apeifjeawpfioj</li>

I want to wrap each group in a <ul></ul> element. How do I do that?

This is what I've tried, but it only matches the individual elements: /<li [^>]*>.*<\/li>/g

https://regex101.com/r/KXEkJz/1

And if I do /<li [^>]*>[\s\S]*<\/li>/g, it produces one giant match.

mythereal
  • 773
  • 9
  • 22
  • You said you want to wrap each "group" in a `
      `. Do you consider them a group if there is only one line break between them? What makes it a group?
    – snollygolly Jun 20 '17 at 01:29
  • Possible duplicate of [RegEx match open tags except XHTML self-contained tags](https://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags) – Spencer Wieczorek Jun 20 '17 at 01:29
  • @snollygolly yes, any `
  • ` element that follows with another `
  • ` element are considered part of the same group. If there are line breaks, newlines, or other text, then that would serve as the boundary for the groups.
  • – mythereal Jun 20 '17 at 01:31