import java.util.regex.*; public class Test1 { public static void main(String[] args){ boolean b = Pattern.matches("[,]*?\\p{ASCII}++",",,,A,BC"); System.out.println(b); } }
String s = ",,,a,bc,,"; String s2 = s.replaceAll("^(,*)(.*?)(,*)$", "$2"); System.out.println(s2);输出结果:a,bc
System.out.println(s.replaceAll("(^,*)|(,*$)", ""));
import java.util.regex.*;
public class Test1
{
public static void main(String[] args){
boolean b = Pattern.matches("[,]*?\\p{ASCII}++",",,,A,BC");
System.out.println(b);
}
}
String s2 = s.replaceAll("^(,*)(.*?)(,*)$", "$2");
System.out.println(s2);输出结果:a,bc