[Project_owners] Help with a regular expression?

David Murray lid2000 at tpg.com.au
Sat Sep 3 18:08:11 EDT 2005

What I'm trying to do is fix nonclosing HTML tags, so they're XHTML 
compatible. Here's what I'm using:

text = text.replace(/<(br|hr|img)([^>]*)([^\/])>/gi, "<$1$2$3 />");

This works, so long as there's a space before the end of the tag. I've 
been trying all afternoon, but I can't come up with one that satisfies 
the following:

<br class="someclass">
<br >
<img src="http://blahblahblah">
<hr style="something: blah;" class="somethingelse">

Doesn't match:
<br />
<img src="http://blahblahblah" />

I thought I had it a few times, but the / in http:// kept screwing me 
up. If anyone wants to give it a go, it'd be much appreciated.


More information about the Project_owners mailing list