Regular Expression to capture the first <p> of HTML
Posted
by Program.X
on Stack Overflow
See other posts from Stack Overflow
or by Program.X
Published on 2010-06-03T15:39:43Z
Indexed on
2010/06/03
15:44 UTC
Read the original article
Hit count: 164
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.)
© Stack Overflow or respective owner