• Post Reply Bookmark Topic Watch Topic
  • New Topic

req Exp  RSS feed

 
Jaan Smith
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Trying to use "xml1.replaceAll("<![CDATA[","");" but it throws

java.util.regex.PatternSyntaxException:

Wondering how to do the replacement.

The following did not work

xml1.replaceAll("<!/[CDATA/[","");
xml1.replaceAll("<!//[CDATA//[","");
Thanks in advance
Jaan
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to use backslashes (\\) not forward slashes (//) to escape things.
 
Paul Clapham
Sheriff
Posts: 22708
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are trying to escape characters in your regex because they have meaning in regexes, then you're doing it wrong. The regex escape character is backslash ("\") and not slash ("/"). Remember also that backslashes have to be escaped for Java as well, so you'll need pairs of backslashes.

Also I think that what you are doing has the possibility of converting well-formed XML to non-well-formed XML, but that's another topic.
 
Jaan Smith
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wondering why it will make an xml a non well defined?
Thanks
Jaan
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!