java从字符串中提取数字
转:
- public boolean isDigit(String strNum) {
- return strNum.matches("[0-9]{1,}");
- }
-
- public boolean isDigit(String strNum) {
- Pattern pattern = Pattern.compile("[0-9]{1,}");
- Matcher matcher = pattern.matcher((CharSequence) strNum);
- return matcher.matches();
- }
-
-
- public String getNumbers(String content) {
- Pattern pattern = Pattern.compile("\d+");
- Matcher matcher = pattern.matcher(content);
- while (matcher.find()) {
- return matcher.group(0);
- }
- return "";
- }
-
- public String splitNotNumber(String content) {
- Pattern pattern = Pattern.compile("\D+");
- Matcher matcher = pattern.matcher(content);
- while (matcher.find()) {
- return matcher.group(0);
- }
- return "";
- }
原文地址:https://www.cnblogs.com/libin6505/p/13433429.html