I'm working with a contenteditable field. When someone pastes data that includes <span... itxt...>...</span> or <a href...rel="nofollow"...>...</a>, I want the tags to be removed.
Here is the exact code I'm using:
a = a.replace(/<span [^>]*?itxt[^>]*?>([\s\S]*?)<\/span>/gi, '$1');
a = a.replace(/<a href=[^>]*?rel=["']nofollow[^>]*?>([\s\S]*?)<\/a>/gi, '$1');
This works 99.9% of the time, but every once in awhile, I'll have something like this come through:
<a href="
http://www.example.com/?start=0&h=20121001202337#" rel="nofollow" id="itxthook1" class="itxtnewhook>whatever</span></a>
Specifically, notice that the class="itxtnewhook doesn't have a closing ", and there's a closing </span> without an opening <span>.
Since this is being modified onPaste, I don't see the text before it's submitted, and I haven't been able to duplicate it myself so I'm guessing that it's related to a specific browser. But can you guys see what I'm missing in my str.replace() script that's letting this slip through?