Reorder Octates in an IPAddressees in Java

I have ip address example "27.96.168.92" and would like to reorder the each Octates in the ip address. so the output should be "92.168.96.27".

I would use a simple regular expression:

String ip = "27.96.168.92";
String switched = ip.replaceAll("(\\d+)\\.(\\d+)\\.(\\d+)\\.(\\d+)", "$4.$3.$2.$1");
System.out.println(switched);

Output

92.168.96.27