title: Extract text between URL with Java
body: <p>I want to extract from this URL: &quot;https://www.newhomesource.com/community/az/cave-creek/galloway-ridge-by-k-hovnanian-homes/148397&quot; the text &quot;k-hovnanian-homes&quot;</p>
  <p>The thing is that I manage to obtain this String: &quot;k-hovnanian-homes/148397&quot; but I can't remove the /148397. Is there a way I can remove it?</p>
  <p>Here is what I have</p>
  <pre><code> import org.openqa.selenium.By;
   import org.openqa.selenium.WebDriver;
   import org.testng.annotations.BeforeTest;
   import org.testng.annotations.Test;
  
   public void VerifyURL(){
      String URL= &quot;https://www.newhomesource.com/community/az/cave-creek/galloway-ridge-by-k- 
      hovnanian-homes/148397&quot;;
     
      String Final = URL.substring(URL.indexOf(&quot;by-&quot;) + 3);
      System.out.println(Final);
  
   }
  </code></pre>
  <p>Also the numbers after the &quot;/&quot; can change so take that in count</p>
  <p>I'm Selenium WebDriver and TestNG so that's why the imports :)</p>
  <p>Update: Another URL example could be: <a href="https://www.newhomesource.com/community/tn/lebanon/hampton-chase-legacy-collection-by-beazer-homes/152012" rel="nofollow noreferrer">https://www.newhomesource.com/community/tn/lebanon/hampton-chase-legacy-collection-by-beazer-homes/152012</a></p>