Java tutorial
//package com.java2s; import java.util.ArrayList; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { public static List<String> getMatches(String regex, CharSequence input) { if (input == null) return null; List<String> matches = new ArrayList<>(); Pattern pattern = Pattern.compile(regex); Matcher matcher = pattern.matcher(input); while (matcher.find()) { matches.add(matcher.group()); } return matches; } }