You can simply use pattern class and matcher class for it. here below the sample code,
Pattern pattern = Pattern.compile(regexString);
// text contains the full text that you want to extract data
Matcher matcher = pattern.matcher(text);
while (matcher.find()) {
String textInBetween = matcher.group(1); // Since (.*?) is capturing group 1
// You can insert match into a List/Collection here
}
test code
String pattern1 = ": "; //give start element
String pattern2 = ","; //end element
String text = "9X1X121: 1001, 1YXY2121: 2001, Role: ZZZZz";
Pattern p = Pattern.compile(Pattern.quote(pattern1) + "(.*?)" + Pattern.quote(pattern2));
Matcher m = p.matcher(text);
while (m.find()) {
if (m.group(1).matches("[+-]?\\d*(\\.\\d+)?")) { //check it's numeric or not
System.out.println(m.group(1));
}
}