package info.bukova.isspst;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class RegExUtils {
	public static List<String> getMatches(String input, String regEx, int group) {
		List<String> list = new ArrayList<String>();
		
		if (!StringUtils.isNullOrEmpty(input) && !StringUtils.isNullOrEmpty(regEx)) {
			Pattern pattern = Pattern.compile(regEx);
			Matcher matcher = pattern.matcher(input);
			int groupCount = matcher.groupCount() + 1;

			if ((groupCount >= 0) && (group < groupCount)) {
				while (matcher.find()) {
					String item = matcher.group(group);
					list.add(item);
				}
			}
		}

		return list;
	}

	public static List<String> getMatches(String input, String regEx) {
		return RegExUtils.getMatches(input, regEx, 0);
	}
}
