import java.util.regex.Matcher; import java.util.regex.Pattern; public class RegexPatternMatch{ public static void main(String[] args) { String str = "Hello, World"; Matcher matcher = Pattern.compile("(.+?), (.+?)$").matcher(str); if (matcher.find()){ System.out.println(matcher.group(1)); //Hello System.out.println(matcher.group(2)); //World } } }