1.当有其他字符出现时,返回的数组长度>1
String s = "3---6\5656";
Pattern pattern = Pattern.compile("[^0-9-]+");
String[] ss = pattern.split(s);
System.out.println(ss.length);
System.out.println(ss[1]);
2.无其他字符出现时,数组长度为 1。
综上所述,我们可以根据返回的数组的长度进行判定。
其中,此次正则 [^0-9-]+ 中 []代表子表达式 ,[^]代表除去的意思,[^0-9-]意思为除去数字和- ,+代表[^0-9-]重复出现1次或多次。