number out of string in java
问题 I have something like "ali123hgj". i want to have 123 in integer. how can i make it in java? 回答1: Use the following RegExp (see http://java.sun.com/docs/books/tutorial/essential/regex/): \d+ By: final Pattern pattern = Pattern.compile("\\d+"); // the regex final Matcher matcher = pattern.matcher("ali123hgj"); // your string final ArrayList<Integer> ints = new ArrayList<Integer>(); // results while (matcher.find()) { // for each match ints.add(Integer.parseInt(matcher.group())); // convert to