日期:2014-05-20 浏览次数:20760 次
//String separator = System.getProperty("line.separator"); String separator = "\n"; //不知道LZ是否按行分割的, //如果不是按行分割,用separator="",也能对应,就是结果只有1行 String s = "@article{AcharyaBI93," + "\n" + "author = \"Acharya, A. and Badrinath, B.R. and Imielinski, T.\"," + separator + "title = \"Impact of Mobility on Distributed Computations\"," + separator + "journal = OSR," + separator + "volume = 27," + separator + "number = 2," + separator + "pages = \"15-20\"," + separator + "month = \"April\"," + separator + "year = 1993" + separator + "}"; System.out.println("----------original----------"); System.out.println(s); s = s.replaceAll("^@article(.*)", "@Article$1").replaceAll("\"(.*?)\"", "{$1}"); StringBuffer buf = new StringBuffer(); Pattern p = Pattern.compile("((?<=("+separator+"[}],|,|))[^,]*?)(\\s*=\\s*.*?("+separator+"|[}],|,))"); Matcher m = p.matcher(s); while (m.find()) { String s1 = m.group(1); System.out.println(m.group(1)); m.appendReplacement(buf, m.group(1).toUpperCase()+"$3"); } m.appendTail(buf); System.out.println("----------after replace----------"); System.out.println(buf);