Can anyone tell me how to write a regular expression to match the comments in XML file, for example,
任何人都可以告诉我如何编写正则表达式来匹配XML文件中的注释,例如,
<!-- Global JNDI resources
Documentation at /docs/jndi-resources-howto.html
-->
I'm using Eclipse (java) and want to remove those comments from XML file.
我正在使用Eclipse(java)并希望从XML文件中删除这些注释。
3 个解决方案
#1
16
xmlFileContent.replaceAll( "(?s)<!--.*?-->", "" );
#2
9
xmlFileContent.replaceAll("<!--[\s\S]*?-->", "");
[\s\S] works like '.', but will consume line endings as well.
[\ s \ S]的工作方式类似于'。',但也会消耗行结尾。
#3
1
xmlFileContent.replaceAll("<!--.*?-->", "");
#1
16
xmlFileContent.replaceAll( "(?s)<!--.*?-->", "" );
#2
9
xmlFileContent.replaceAll("<!--[\s\S]*?-->", "");
[\s\S] works like '.', but will consume line endings as well.
[\ s \ S]的工作方式类似于'。',但也会消耗行结尾。
#3
1
xmlFileContent.replaceAll("<!--.*?-->", "");