If I have HTML like this:
<dsometext<f<legit></legit> whatever
What regex pattern do I use to switch <
to <
before d and f.
I think it's all <
which are not followed by a >
but I can't wrap the regex for that around my head. I have users typing HTML and then am using jQuery to wrap the HTML and parse the nodes, however bad interim markup blows it up, so I want to swap out the <
Ideas?
Edit
I'm not trying to parse the HTML to valid HTML. I just want to knock out interim characters as users type and the HTML is updated on page. If they are typing <strong>
, and are still at the <
and I try to put the HTML on the page, it will cause horrible markup. That's why I need to swap it out.
Answer I chose @pimvdb's answer because it correctly answers the question I asked.
However to make the world happier, I found a much simpler way of doing things without using any regex. Basically I had an issue originally where [title] was in place of an element and it had no container element, guaranteed to just contain the title. Therefore changing innerHTML of anything would cause horrors. We simply added the wrapping element. The hesitation to do that and the cause of this thread was due to some crazy reasons specific to the app and backwards comparability for our users.