【发布时间】:2011-10-26 03:31:24
【问题描述】:
我试图替换文件中出现的单词,除非它包含在字符串中:
所以我应该在
中替换this
The test in this line consists in ...
但不应该匹配:
The test "in this line" consist in ...
这就是我正在尝试的:
line.replaceAll( "\\s+this\\s+", " that ")
但在这种情况下它失败了,所以我尝试使用:
line.replaceAll( "[^\"]\\s+this\\s+", " that ")
但也不行。
任何帮助将不胜感激
【问题讨论】:
-
那么这个场景中的字符串不包含转义字符?
-
没错,我应该忽略字符串中的任何内容...
标签: java regex replaceall