1

I'm having a bit of trouble with a couple of regex's that I almost got working earlier. I basically need to remove HTML comments from either side of a specific <span> tag.

This is what I have so far:

.replace(/<!--<span aria-hidden=\"true\" data-icon=\"e\"/,
         '<span aria-hidden="true" data-icon="e"')

.replace(/onclick=\"deletetodo(this)\"><\/span>-->/, 
         'onclick="deletetodo(this)"></span>');

Maybe I've been staring at this for too long and I can't spot an obvious mistake, but if anyone knows why this wont get rid of the <!-- and --> tags, you'd be saving me a massive headache!

Thanks.

[edit] Multi-lined for SO only, in code they're on a single line. [/edit]

lukeseager
  • 2,365
  • 11
  • 37
  • 57

1 Answers1

2

The parentheses should be escaped in regex when they are part of the string; you should try:

.replace(/onclick=\"deletetodo\(this\)\"><\/span>-->/, ...

instead of

.replace(/onclick=\"deletetodo(this)\"><\/span>-->/, ...
tomcaa
  • 130
  • 4