Reputation: 43
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.
Upvotes: 0
Views: 164
Reputation: 25165
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>/,"");
Upvotes: 0
Reputation: 66364
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.
Upvotes: 2