$re = '/<li>(?>[^<]+|(<[uo]l)>|<(?!\/?li)[^>]*>|(?R))*<\/li>(?(1)|(*F))/m';
$str = '<li>Hi</li> - Just some text, should ignore
<li><ul><li>hi</li></ul></li> - Directly in <li>
<li>Hi<ul><li>hi</li></ul></li> - Plain text before the nested list
<li><strong>Hi</strong><ul><li>hi</li></ul></li> - HTML content before the nested list
<ul><li>list item 1</li></ul>
<ul><li>list item 1</li><li><ol><li>2.1</li><li>2.2</li><li>2.3</li></ol></li><li>list item 3</li></ul>
<ul><li>list item 1</li><li>asdasdas<ol><li>2.1</li><li>2.2</li><li>2.3</li></ol></li><li>list item 3</li></ul>
<ul><li>list item 1</li><li><strong>asdasdas</strong><ol><li>2.1</li><li>2.2</li><li>2.3</li></ol></li><li>list item 3</li></ul>
';
preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);
// Print the entire match result
var_dump($matches);
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for PHP, please visit: http://php.net/manual/en/ref.pcre.php