Ok, now that I've understand what you need , here's the solution:
I've written alot of stuff and prints so you can easly understand the code.
Basically first I've putted your rules into a map, and based on user input I'm separating sender from receiver, and if the input ends with char "%", then it is used as wildcard.
You can test differente outputs by commenting / uncommenting the differente input that I've put in the code.
Let me know :)
HashMap<String,String> map = new HashMap<>();
map.put("IR", "Australia");
map.put("London", "US");
map.put("UK", "CANADA");
String input = "London, Australia"; //false
// String input = "Lon%, US"; //true
// String input = "Lon%, U%"; //true
// String input = "U%, CANADA"; //true
StringTokenizer token = new StringTokenizer(input,",");
String senderInput = token.nextToken();
System.out.println("Sender:"+senderInput);
for(String senderMap : map.keySet()){
boolean firstCondition;
if(senderInput.endsWith("%")) {
String senderMatch = senderInput.replace("%", "");
firstCondition = senderMap.startsWith(senderMatch);
}else {
firstCondition = senderMap.equals(senderInput);
}
if(firstCondition){
System.out.println("Sender matched with "+senderMap);
String receiverInput = token.nextToken().replaceAll(" ","");
System.out.println("Receiver:"+receiverInput);
String receiverMap = map.get(senderMap);
boolean secondCondition;
if(receiverInput.endsWith("%")) {
String receiverMatch = receiverInput.replace("%", "");
secondCondition = receiverMap.startsWith(receiverMatch);
}else {
secondCondition = receiverMap.equals(receiverInput);
}
if(secondCondition){
System.out.println("MATCHING!");
}else{
System.out.println("NOT MATCHING!");
}
}
}