我对多行字符串的replaceAll有问题:
String regex = "\\s*/\\*.*\\*/";
String testWorks = " /** this should be replaced **/ just text";
String testIllegal = " /** this should be replaced \n **/ just text";
testWorks.replaceAll(regex, "x");
testIllegal.replaceAll(regex, "x");
Run Code Online (Sandbox Code Playgroud)
以上适用于testWorks,但不适用于testIllegal !? 为什么这样,我怎么能克服这个?我需要替换类似注释/*...*/的内容,它跨越多行.
我想创建一个ant目标,它可以替换不以定义模式开头的文件(或更多)的内容.有没有使用ant和replaceregexp的解决方案?或者替代这个?例:
我想将foo.txt的文本更改为:"这只是foo"