import java.util.regex.*; public class RegEx { public static void main(String args[]) { // The parenthesis define the groups Pattern p = Pattern.compile("([a-z]+)@([0-9]+)"); Matcher m = p.matcher("mary@123john@456luis@4HOUSE@134"); while (m.find()) { System.out.print("m.group():" + m.group() + " "); System.out.print("m.group(1):" + m.group(1) + " "); System.out.println("m.group(2):" + m.group(2) + " "); } } }