How to trim/cut string in java by symbol?
<p>I'm working on a project where my API returns url with id at the end of it and I want to extract it to be used in another function. Here's example url:</p>

<pre><code> String advertiserUrl = http://../../.../uuid/advertisers/4 &lt;&lt;&lt; this is the ID i want to extract.
</code></pre>

<p>At the moment I'm using java's string function called substring() but this not the best approach as IDs could become 3 digit numbers and I would only get part of it. Heres my current approach:</p>

<pre><code>String id = advertiserUrl.substring(advertiserUrl.length()-1,advertiserUrl.length());
System.out.println(id) //4
</code></pre>

<p>It works in this case but if id would be e.g "123" I would only get it as "3" after using substring, so my question is: is there a way to cut/trim string using dashes "/"? lets say theres 5 / in my current url so  the  string would get cut off after it detects fifth dash? Also any other sensible approach would be helpful too. Thanks.</p>

<p>P.s uuid in url may vary in length too</p>