java 正则表达式替换首尾字符或符号
private String replaceStr(String str){ Pattern pattern = Pattern.compile("^,+|,+$"); Matcher matcher = pattern.matcher(str); return matcher.replaceAll(""); } String newStr = replaceStr(",222,3344,344,,,,,"); System.out.println(newStr);//-----222,3344,344
时间: 2024-11-08 16:18:04