RegEx match open tags except XHTML self-contained tags
Posted
by Jeff
on Stack Overflow
See other posts from Stack Overflow
or by Jeff
Published on 2009-11-13T22:38:26Z
Indexed on
2010/04/05
1:43 UTC
Read the original article
Hit count: 625
I need to match all of these opening tags:
<p>
<a href="foo">
But not these:
<br />
<hr class="foo" />
I came up with this and wanted to make sure I've got it right. I am only capturing the a-z
.
<([a-z]+) *[^/]*?>
I believe it says:
- Find a less-than, then
- Find (and capture) a-z one or more times, then
- Find zero or more spaces, then
- Find any character zero or more times, greedy, except
/
, then - Find a greater-than
Do I have that right? And more importantly, what do you think? =)
EDIT:
Hmm, which answer to mark as correct? For the record, ALL the answers are appreciated. Many thanks!
© Stack Overflow or respective owner