title: Splitting a string into words and punctuation with Ruby
body: <p>I'm working in Ruby and I want to split a string and its punctuation into an array, but I want to consider apostrophes and hyphens as parts of words.  For example, </p>
  
  <pre><code>s = "here...is a     happy-go-lucky string that I'm writing"
  </code></pre>
  
  <p>should become </p>
  
  <pre><code>["here", "...", "is", "a", "happy-go-lucky", "string", "that", "I'm", "writing"].
  </code></pre>
  
  <p>The closest I've gotten is still inadequate because it doesn't properly consider hyphens and apostrophes as part of the word.  </p>
  
  <p>This is the closest I've gotten so far: </p>
  
  <pre><code>s.scan(/\w+|\W+/).select {|x| x.match(/\S/)}
  </code></pre>
  
  <p>which yields </p>
  
  <pre><code>["here", "...", "is", "a", "happy", "-", "go", "-", "lucky", "string", "that", "I", "'", "m", "writing"]
  </code></pre>
  
  <p>.</p>