以下方法可把字符串中的数字取出:
String attr = "ls87495j513fJY1s31sdFS3f21s31";
String regEx = "[^0-9]";
Pattern compile = Pattern.compile(regEx);
Matcher matcher = compile.matcher(attr);
String trim = matcher.replaceAll("").trim();
正则表达式表示匹配除数字以外的字符,然后replaceAll方法使用空字符代替匹配的字符,这样剩下的字符串就只包括数字。最后只需要将trim转换为int类型就结束了
也可以看下这个链接 https://www.cnblogs.com/android-html5/archive/2012/06/02/2533926.html