Java正则表达式在非注释中查找特殊字符

时间:2013-02-04 09:52:13

标签: java regex eclipse replace

在我将工作区编码切换为UTF-8并返回(Windows-ISO)之后,我的所有(德语)变音都​​转换为了�。

我想用Eclipse Find / Replace替换所有的静态引用。

public interface StringConstants {
    public static final String ae = "\u00E4";
    public static final String oe = "\u00F6";
    public static final String ue = "\u00FC";
    public static final String AE = "\u00C4";
    public static final String OE = "\u00D6";
    public static final String UE = "\u00DC";
    public static final String ss = "\u00DF";
}

我不想替换所有评论,因为没有人关心它们......

到目前为止,我可以用

做到这一点
Find: ^[^//](.*?)(�)+

Replacement: $1" + StringConstants.ue + "

它会省略CVS评论

// �ber

但它不适用于在它们前面有空格或代码的注释和阻止注释。 e.g:

doSomething(); // blabla �ber // <-- should be omitted
/** 
 * �ber // <-- should be omitted
 */
\t// �ber // <-- should be omitted
log.debug("�ber"); // <-- should be replaced

我试着写一个正则表达式,它应该省略//之前任何字符的注释,但它不起作用。

(背景:在该代码的任何文档中都没有定义的Charset,甚至在VCS中也没有。我是这个工具的最后一个开发人员,所有其他开发人员都不见了。代码是在windows下为Linux上的tomcat开发的 - AppUsers也有Windows)

有人可以帮助我吗?

干杯, 马丁

1 个答案:

答案 0 :(得分:0)

这个怎么样:

^(?:(?!//|(?:\*\s)).)*(�)+.*

这里你需要用你想要的文本替换组1(唯一的组)。 正则表达式搜索“�”前面没有'//'或'* \ s'的行

相关问题