I have a program in which i'm creating TelephoneNumber objects which have ints areaCode exchangeCode and number. I'm using a regex to make sure that the input is an actual phone number. I want to know if there is a way to use a back reference to assign the first three numbers to areaCode, the second 3 to exchange code and the last 4 to number. My code is below

Java Code:
private static int areaCode, exchangeCode, number;
 public TelephoneNumber(String phoneNumber){
    Pattern pattern = Pattern.compile("(\\d{3})-(\\d{3})-(\\d{4})");
    Matcher matcher = pattern.matcher(phoneNumber);
    if(matcher.matches())
        System.out.println("valid phone number");
    else 
        System.out.println("invalid phone number");
    }
Back reference 1 needs to equal to areaCode, 2 equal to exchangeCode and 3 to number but I don't know how to do this.