//定义正则 String regex = "^,*|,*$"; String str =",,3453,435,45,34543,,"; String str1 = str.replaceAll(regex, "");