title: Ruby regular expressions for finding words
body: <p>I'm quite new to regular expressions. I am using the regular expression:</p>
  
  <pre><code>/\w+/
  </code></pre>
  
  <p>To check for words, and it's obvious that this will have problems with punctuation, but I'm not quite sure how to change this regular expression. For example, when I run this command from a class I made:</p>
  
  <pre><code>Wordify.new.regex(/\w+/).string("This sentence isn't 'the best-example, isn't it not?...").display
  </code></pre>
  
  <p>I get the output:</p>
  
  <pre><code>-----------
  this: 1
  sentence: 1
  isn: 2
  t: 2
  the: 1
  best: 1
  example: 1
  it: 1
  not: 1
  -----------
  </code></pre>
  
  <p>How can I adjust the regular expression so that it matches words with apostrophes, like: <strong>isn't</strong> as one word, but will only match <strong>the</strong> when searching <strong>'the</strong> or <strong>the'</strong>. Hyphens in the middle of a word like <strong>stack-overflow</strong> should match return <strong>stack</strong> and <strong>overflow</strong> separately, which this already does.</p>
  
  <p>Additionally, words shouldn't be able to start or end with numbers, like <strong>test1241</strong> or <strong>436test</strong> should become <strong>test</strong>, but <strong>te7st</strong> is okay. Plain numbers should not be recognised. </p>
  
  <p>Sorry, I know this is a big ask, but I'm not sure where to start with regex. Would be grateful if you could also explain what the expression means if possible.</p>