小编Rob*_*ert的帖子

Java正则表达式替换所有多行

我对多行字符串的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 !? 为什么这样,我怎么能克服这个?我需要替换类似注释/*...*/的内容,它跨越多行.

java regex replaceall

45
推荐指数
3
解决办法
3万
查看次数

Ant替换不以.开头的文件文本

我想创建一个ant目标,它可以替换不以定义模式开头的文件(或更多)的内容.有没有使用ant和replaceregexp的解决方案?或者替代这个?例:

  • 我有文件boo.txt,其中包含文字:"这是嘘".
  • 我还有文件foo.txt,其中包含文本:"just foo".

我想将foo.txt的文本更改为:"这只是foo"

regex ant file-io regex-negation

1
推荐指数
1
解决办法
6027
查看次数

标签 统计

regex ×2

ant ×1

file-io ×1

java ×1

regex-negation ×1

replaceall ×1