title: Java Regex pattern to match string with apostrophes
body: <p>I need to match a pattern to strip the <code>'s</code> as well as the ending <code>'</code> from words. I've used the regex pattern:</p>
  
  <pre><code>(\\w+)('s$|s'$|'$). 
  </code></pre>
  
  <p>I need the first group. However what is happening with this pattern is a word like <code>cats'</code> matches with the third pattern i.e <code>'$</code>. Hence my <code>group(1)</code> still has <code>cats</code>. I tried using the pattern:</p>
  
  <pre><code>(\\w+)('s$|s'$|([^s] &amp; '$).
  </code></pre>
  
  <p>But here what happens is for a word <code>abc'</code> group 1 has just <code>ab</code> and group 2 has <code>c'</code>. Any suggestions on how to handle this.</p>