0

Hi I am having string contents <xml>.....</xml>
I want to replace xml tag with its inner content with the empty string. How can I achieve it by regular expression or javascript.

My Code is -

var tempHtml =  "Test Data Test Data<br>Test data Test Data data ata<br>data<br><br>Testerbr><br><!--[if gte mso 9]><xml> AAAAAAAAAAAAAAA </xml><![endif]--><!--[if gte mso 9]><xml>BBBBBBBBBBBBBBB</xml><![endif]--><!--[if gte mso 9]><xml> CCCCCCCCCCCCC </xml><![endif]--> here data";


ht = ht.replace("<xml>(.+?)<\/xml>/gi", "");

1 Answer 1

2

The regex just needed to be modified, alongside with using the right variable name:

var tempHtml =  "Test Data Test Data<br>Test data Test Data data ata<br>data<br><br>Testerbr><br><!--[if gte mso 9]><xml> AAAAAAAAAAAAAAA </xml><![endif]--><!--[if gte mso 9]><xml>BBBBBBBBBBBBBBB</xml><![endif]--><!--[if gte mso 9]><xml> CCCCCCCCCCCCC </xml><![endif]--> here data";
tempHtml = tempHtml.replace(/<xml>(.+?)<\/xml>/gi, "");
// Now tempHtml = "Test Data Test Data<br>Test data Test Data data ata<br>data<br><br>Testerbr><br><!--[if gte mso 9]><![endif]--><!--[if gte mso 9]><![endif]--><!--[if gte mso 9]><![endif]--> here data"
Sign up to request clarification or add additional context in comments.

9 Comments

Thanks for the reply
But not this is not working with my actual string. Actual string is too big will share with you in couple of minutes
can you share the "actual string" ?
In the code linked, the regex is wrapped with double quotes ("). Remove the double quotes so the second line will be tempHtml = tempHtml .replace(/<xml>(.+?)<\/xml>/gi, "");.
thanks again Still one problem just come to knoe Its working fine in chrome but not in my mozilla (little old version 40.0.3 ) Can you pleas check.
|

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.