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]

3
  • Maybe there is more whitespace in the original string? HTML tends to be like that. Commented Feb 12, 2013 at 23:33
  • 1
    try wrapping pattern strings in single quotes instead of / / Commented Feb 12, 2013 at 23:58
  • How are you using that, for what do you need it? Seems you are misusing regex Commented Feb 13, 2013 at 0:01

1 Answer 1

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>-->/, ...
Sign up to request clarification or add additional context in comments.

1 Comment

Doing this, plus the suggested: swap \" with just ' worked like a charm!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.