0

I want to replace object tag containing string in javascript with spaces.

var tmpSearchPhrase ='<object data="data:text/html;
base64,PHNjcmlkb21haW4pOzwvc2NyaXB0Pg=="></object>';
tmpSearchPhrase.replace(/<object .*>.*<\/object>/,"");   

But it is not replacing object.

2 Answers 2

2

You can't have a new line literal in a String, unless you escape it.

var tmpSearchPhrase ='<object data="data:text/html;
base64,PHNjcmlkb21haW4pOzwvc2NyaXB0Pg=="></object>';
// SyntaxError: Unexpected token ILLEGAL

var tmpSearchPhrase ='<object data="data:text/html;\
base64,PHNjcmlkb21haW4pOzwvc2NyaXB0Pg=="></object>';
// fine

tmpSearchPhrase.replace(/<object .*>.*<\/object>/,"");  // ""

You may also be forgetting to assign the result of replace to a variable.

Sign up to request clarification or add additional context in comments.

Comments

0

Don't break the string and re-assign the return value of replace to tmpSearchPhrase

tmpSearchPhrase ='<object data="data:text/html;base64,PHNjcmlkb21haW4pOzwvc2NyaXB0Pg=="></object>';
tmpSearchPhrase = tmpSearchPhrase.replace(/<object .*>.*<\/object>/,"");   

Comments

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.