Sorry I didn't explain it very well. If I have a URL such as http://www.somedomain.com/this_page.html I don't want to do anything. On the other hand, if I have a URL such as http://10.1.1.1/this_dir/this_page.html I wish to extract the IP address which in this case would be 10.1.1.1.
Looks like your first solution just might do the trick!