java正则表达式 我想把有z字符串中的“},{”的替换为“}},{”用pattern 和matcher 怎么写

如题所述

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class RegEx {

public static void main(String[] args) {

String pattern = "\\}, \\{";
String replacement = "}}, {";
String z = "{(3, 4, 5), {6,} {}, {7}, {8}, {10}, [11]}";
String result = new String();

Pattern p = Pattern.compile(pattern);

Matcher m = p.matcher(z);

if (m.find()) {
result = m.replaceAll(replacement);
} else {
System.out.println("No Match.");
return;
}

System.out.println("Original String: \n" + z +
"\nResult String: \n" + result);

}
}


结果如下:


温馨提示:答案为网友推荐,仅供参考

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网