Well, regex are not well suited to parsing HTML (use DomDocument for that). You also said that you want to "match on". Does that mean capture? Replace? "Check for"? Assuming check for, here's a crude one:
$regex = '#(?i:<p[^>]*>[^\\n]*)(\\n)(?i:[^<]*</p>)#';
It won't match <p><i>foo\n</i></p>
, but it will match the case where there is a new line inside of a basic <p>
tag (with no html children).
What I'd suggest, is grabbing DomDocument, and doing something like this:
$dom = new DomDocument();
$dom->loadHTML($html);
$pTags = $dom->getElementsByTagName('p');
foreach ($pTags as $p) {
$txt = $p->textContent;
if (strpos($txt, "\n") !== false) {
//You found a \n within a P tag
}
}