如题所述
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);
}
}
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);
}
}
结果如下:
温馨提示:答案为网友推荐,仅供参考