Java tutorial
//package com.java2s; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { public static int getFirstNumber(String StringWithNumber) { return Integer.parseInt(get("\\d+", StringWithNumber, 0)); } public static String get(String regex, String content, int groupIndex) { Matcher matcher = Pattern.compile(regex, Pattern.MULTILINE).matcher(content); if (matcher.find()) { return matcher.group(groupIndex); } return null; } }