I want to match first empty P tag for each DIV and insert some text. I am using (<p[^>]*>)(</p>)
this regular expression which is matching to all P tags inside DIV.
var yourDivString = "<DIV WITH Paragraph Tag(s) and many other tags>";
yourDivString = Regex.Replace(yourDivString , "(<p[^>]*>)(</p>)", "THIS IS FIRST EMPTY P TAG in EACH DIV")
Example:
<div>
<p></p>
<p></p>
</div>
Excepted Output:
<div>
<p>THIS IS FIRST EMPTY P TAG in EACH DIV</p>
<p></p>
</div>
Note: we are not using any HTML files to parse. Its only a few strings.