If you use Pattern and Matcher to execute your regular expression, you can query Matcher for each group using the int group method
So:
Pattern p = Pattern.compile("(\\d{1-3}).(\\d{1-3}).(\\d{1-3}).(\\d{1-3})");
Matcher m = p.matcher("127.0.0.1");
if (m.matches()) {
System.out.print(m.group(1));
}
source
share