Can anyone guide me on writing regularexp that I would use in my java code for extracting just the ip from
http://10.22.14.152/something/api
expected result: 10.22.14.152
Can anyone guide me on writing regularexp that I would use in my java code for extracting just the ip from
http://10.22.14.152/something/api
expected result: 10.22.14.152
use the structure of the URL to fashion very simple regular expression:
http://(.*?)/
Just to show a different way to do this, (though sweaver2112's answer is much better)...
You know the format will be in the form of (http:)//(ipaddress)/(directory)/(directory)... You can split around the /
and grab the 3 element in the array to get the IP...
String url = "http://10.22.14.152/something/api";
String[] splitUp = url.split("/");
String ipAddress = splitUp[2];