我有一个字符串字符串分割方法在开始时
String text="abc19xyz87nag";
我需要只出它的数量只剩下空空的令牌,所以我申请"\\D+"
正则表达式如下,
String text="abc19xyz87nag";
String[] tks=text.split("\\D+");
但我在阵列的开头看到一个空的标记
我怎么会发现另外两个s olutions反正如下
使用扫描仪
Scanner sc = new Scanner(text).useDelimiter("\\D+");
while(sc.hasNext()) {
System.out.println(sc.nextInt());
}
使用Pattern和Matcher
Matcher m = Pattern.compile("\\d+").matcher(text);
while (m.find()) {
System.out.println(m.group());
}
那么,为什么字符串分割在开始时留下空的令牌?
我是否需要更改正则表达式以避免它?
任何帮助表示赞赏
另请参阅http://stackoverflow.com/q/19503283/1679863 –
@RohitJain - 我必须对正则表达式进行的更改不会在该副本中提供 – gowtham
它是。清楚地浏览它,然后看看结尾。 –