title: Java Regex: Remove Everything After Last Instance Of Character
body: <p>Say I have a string: </p>
  
  <pre><code>/first/second/third
  </code></pre>
  
  <p>And I want to remove everything after the last instance of / so I would end up with:</p>
  
  <pre><code>/first/second
  </code></pre>
  
  <p>What regular expression would I use? I've tried:</p>
  
  <pre><code>String path = "/first/second/third";
  String pattern = "$(.*?)/";
  Pattern r = Pattern.compile(pattern2);
  Matcher m = r.matcher(path);
  if(m.find()) path = m.replaceAll("");
  </code></pre>