0

from XML string I want to remove

]]><![CDATA[

i tried in following way :

var find = "]]><![CDATA[";
var re = new RegExp(find, 'g');
xmldata = xmldata.replace(re, '');

its giving error : Uncaught SyntaxError: Invalid regular expression: //]]>

what is the issue ?

3
  • 2
    "]]><![CDATA[" that's not a regular expresion, use the standar replace instead. [ xmldata = xmldata.replace(find, ''); ] Commented Mar 10, 2014 at 12:08
  • @frikinside will it replace all such string ? Commented Mar 14, 2014 at 4:50
  • Sadly... don't. This it will only replace the first ocurrence. If you need to replace all concurrences you'd be forced to use RegExp. In that case, go for @CasimitEtHippolyte way. I usually create a ` replaceAll` function when loop the replace until no ocurrences left. Commented Mar 14, 2014 at 7:51

1 Answer 1

3

You must escape the opening square brackets:

]]><!\\[CDATA\\[
Sign up to request clarification or add additional context in comments.

1 Comment

@Chintan_chiku: thanks, however frikinside's alternative seems to be the best way for your specific case.

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.