We can also capture groups using regular expressions. () is used to specify the group. We use {} to specify the no of occurrences.

Java Code:
String patternStr = "Programming is (Java){3}. Plateform independence.";

Pattern pattern = Pattern.compile(patternStr);

CharSequence inputStr =  "Programming is JavaJavaJava. Plateform independence.";
Matcher matcher = pattern.matcher(inputStr);

if(matcher.find())

{
int start = matcher.start();
int end = matcher.end();
System.out.println(inputStr.subSequence(start, end));
}
else
System.out.println("Pattern is not found.");