Here's the solution.
Please note that you have to use word boundaries \b to get ONLY 4 numbers at the end of the phone number!
Also the group for the space(s) and the "-" looks like this: (\\s+|-) to refer to it later when checking use: (\\2) - the second group; Check line #10 for the actual regex;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Pr_02_MatchPhoneNumber {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String input;
Pattern pattern = Pattern.compile("(\\+359)(\\s+|-)(2)(\\2)([\\d]{3})(\\2)([\\d]{4}\\b)");
while (!(input = scanner.nextLine()).equals("end")) {
Matcher matcher = pattern.matcher(input);
if (matcher.find()) {
System.out.println(input);
}
}
}
}