title: Can I perform stemming using regular expressions?
body: <p>How can I get my regular expression to match against just <strong>one condition</strong> exactly?</p>
  
  <p>For example I have the following regular expression:</p>
  
  <pre><code>(\w+)(?=ly|es|s|y)
  </code></pre>
  
  <p>Matching the expression against the word "glasses" returns:</p>
  
  <pre><code>glasse
  </code></pre>
  
  <p>The correct match should be:</p>
  
  <pre><code>glass (match should be on 'es' rather than 's' as in the match above)
  </code></pre>
  
  <p>The expression should cater for any kinds of words such as:</p>
  
  <pre><code>films
  lovely
  glasses
  glass
  </code></pre>
  
  <p>Currently the regular expression is matching the above words as:</p>
  
  <pre><code>film - correct
  lovel - incorrect
  glasse - incorrect
  glas - incorrect
  </code></pre>
  
  <p>The correct match for the words should be:</p>
  
  <pre><code>film
  love
  glass
  glass
  </code></pre>
  
  <p>The problem I am having at the moment is I am not sure how to adjust my regular expression to cater for either 's' or 'es' exactly, as a word could contain both such as "glasses".</p>
  
  <h2>Update</h2>
  
  <p>Thank you for the answers so far. I appreciate the complexity of stemming and the requirement of language knowledge. However in my particular case the words are finite (films,lovely,glasses and glass) and so therefore I will only ever encounter these words and the suffixes in the expression above. I don't have a particular application for this. I was just curious to see if it was possible using regular expressions. I have come to the conclusion that it is not possible, however would the following be possible:</p>
  
  <p>A match is either found or not found, for example match glasses but NOT glass but DO match films:</p>
  
  <pre><code>film (match) - (films)
  glass (match) - (glasses)
  glass (no match) - (glass)
  </code></pre>
  
  <p>What I'm thinking is if there is a way to match the suffix exactly against the string from the end. In the example above 'es' match glass(es) therefore the condition 's' is discarded. In the case of glass (no match) the condition 's' is discarded because another 's' precedes it, it does not match exactly. I must admit I'm not 100% about this so my logic may seem a little shakey, it's just an idea.</p>