Here you can find the source of getNumber(String string)
public static int getNumber(String string)
//package com.java2s; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { public static int getNumber(String string) { int result = 0; Matcher m;//from ww w .j ava2s . c om String regEx = "[^0-9]"; Pattern p = Pattern.compile(regEx); if (string != null) { m = p.matcher(string); result = Integer.valueOf(m.replaceAll("").trim()); } return result; } }