<br[^<>]*>(?=\s*<(?!br))
should do what you want. (See it here)
Explanation of the regex:
<br # Match <br
[^<>]* # followed by any number of non-bracket characters
> # and a >.
(?= # Assert that we are right before...
\s* # optional whitespace,
< # followed by any tag
(?!br) # except br
) # (End of lookahead)
Some comments:
- I've removed the optional slashes from your regex because
</br>
doesn't exist in HTML or XHTML. - I've also removed the optional spaces at the start of the tags because there may be no whitespace between
<
and the tag name (nor may there be whitespace between/
and>
). - As an aside: In valid XHTML,
<br />
is the only legal form;<br id="foo" />
is invalid.