在myeclipse中,我想替换如下值:
AAAInf aaa = new AAA();
BBBInf bbb = new BBB();
BCEInf ebc = new BCE();
替换成:
AAAInf aaa = new org.rf.Util.mapping(AAAInf.class);
BBBInf bbb = new org.rf.Util.mapping(BBBInf.class);
BCEInf ebc = new org.rf.Util.mapping(BCEInf.class);
请看截图,我已经用正则表达式查询出需要替换内容,但在替换时出现了问题。我该如何编写?请告之。
搜
code="RegExp"(Inf.+?)\1();[/code]
替
[code="RegExp"]\1\2new org.rf.Util.mapping(\1Inf.class);[/code]
eclipse 3.7通过
分都不给还想别个帮你搞 哈哈。
单个文件用带列编辑的编辑器可以处理。
多个文件就不晓得了。
推荐个编辑器sublime_text,列编辑蛮方便的。
myeclipse的那个正则不好用,而且那个全文替换不能使用正则
自己写个java类,把java文件都修改变
[code="java"]
static void test(){
//AAAInf aaa = new org.rf.Util.mapping(AAAInf.class);
// BufferedReader br = null; BufferedWriter wr = null; br = new BufferedReader(new FileReader(f));
//String str =br.readline();
String str = "AAAInf aaa = new AAA();";
Pattern p = Pattern.compile("(\w+)Inf(.*?)(\1\(\))");
Matcher m = p.matcher(str);
String tmp="";
if(m.find()){
tmp = "org.rf.Util.mapping("+m.group(1)+".class)";
str = str.replace(m.group(3), tmp);
}
System.out.println(str);
}
[/code]