Q:

How can I use a regular expression to detect a list or enumeration in PHP

I'm getting data from an XML feed. I can't control the feed nor it's content.
Sometimes, the data contains a list / enumeration. I want to parse this as a clean HTML unordered list.
The data I receive will be in a format like this:
<p>Some text in a paragraph tag</p>
<p>
- List item one <br>
- List-item-two<br>
-List item three  <br>
- Listitem four<br>
</p>
<p>Another paragraph with text, and maybe even more paragraphs after this one!
They might even contain - dashes - - -  or <br><br> breaks!</p>

Note that not every list item is neatly formatted. Some contain trailing paces between the <br>tag or between the dash and the text.
How can I postprocess this in PHP to get this result:
<p>Some text in a paragraph tag</p>
<p><ul>
    <li>List item one</li>
    <li>List-item-two</li>
    <li>List item three</li>
    <li>Listitem four</li>
</ul></p>
<p>Another paragraph with text, and maybe even more paragraphs after this one! 
They might even contain - dashes - - -  or <br><br> breaks!</p>

Can I do it with a regular expression? If so, what would it look like?

A:

Yes, I think regex are a good start point. Have a look to preg_replace
The regex could be something like this (not tested) :
$li = preg_replace('/^-([a-z]+)(<br>)?$/i', '<li>$1</li>', $entry);

Of course this is not working (you need support for whitespace and so on), but I think you get the idea.

A:

You can get started by replacing ^-\s*\b(.+)\b\s*<br>$ with <li>$1</li>. I'll leave the hard part of wrapping it all in a <ul/> up to you.

