Regular Expression to capture the first <p> of HTML
- by Program.X
I have the following regular expression:
(?:<(?<tag>\w*)>(?<text>.*)</\k<tag>>)
I want it t grab the text within the first HTML element.
eg.
<p>This should capture</p>This shouldn't
Works, but ...
<p>This should capture</p><p>This shouldn't</p>
Doesn't work. As you'd expect, it returns:
This should capture</p><p>This shouldn't
I'm racking my brains here. How can I just have it select the FIRST inner text?
(I'm trying to be tag-agnostic, so <strong>This should match</strong> is equally appropriate, etc.)