fork download
import java.util.*;
import java.lang.*;
import java.io.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;


class Ideone
{
	public static void main (String[] args) throws java.lang.Exception
	{
		final String regex = "(?:\\w+|\\G(?!^))\\h*,\\h*([0-9]+)";
		final String string = "sdfs6df -> no capture\n\n"
			 + "fdg4dfg, 5 -> capture 5\n\n"
			 + "fhhh3      ,     6,8    , 7 -> capture 6 8 and 7\n\n"
			 + "asdasd1,4,2,7 -> capture 4 2 and 7";
		
		final Pattern pattern = Pattern.compile(regex);
		final Matcher matcher = pattern.matcher(string);
		
		while (matcher.find()) {
		    System.out.println(matcher.group(1));
		}
	}
}
Success #stdin #stdout 0.09s 34060KB
stdin
Standard input is empty
stdout
5
6
8
7
4
2
7