Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex to remove comments in XML file in Eclipse java

Tags:

java

regex

Can anyone tell me how to write a regular expression to match the comments in XML file, for example,

<!-- Global JNDI resources
   Documentation at /docs/jndi-resources-howto.html
-->

I'm using Eclipse (java) and want to remove those comments from XML file.

like image 540
unix55 Avatar asked Jul 24 '11 04:07

unix55


3 Answers

xmlFileContent.replaceAll( "(?s)<!--.*?-->", "" );
like image 155
nobody Avatar answered Oct 07 '22 03:10

nobody


xmlFileContent.replaceAll("<!--[\s\S]*?-->", "");

[\s\S] works like '.', but will consume line endings as well.

like image 34
MVH Avatar answered Oct 07 '22 03:10

MVH


xmlFileContent.replaceAll("<!--.*?-->", "");
like image 41
Murali VP Avatar answered Oct 07 '22 01:10

Murali VP