Extracting the hostname/ip address from an URL in Android
<p>Let's say I saved a URL of <a href="http://192.168.0.123:321" rel="nofollow">http://192.168.0.123:321</a>. I just want to extract 192.168.0.123.I can do this by using this method
<code>url.toString().substring(7,(url.length()-4));</code></p>

<p>But what if the saved URL is <a href="http://192.168.0.1:12" rel="nofollow">http://192.168.0.1:12</a> ?How do I automatically extract just the IP address?Because the method I just used would display <code>192.168.0.</code> instead </p>

<p><strong>EDIT</strong>
I am using Java on Android Studio</p>

<p><strong>EDIT 2</strong>
I used</p>

<p><code>str = url.toString();
ip = str.substring(str.indexOf('/')+1, str.lastIndexOf(':');</code></p>

<p>because the second one made me crash and I could not find ways to fix it</p>