title: Split by multiple delimiters in Ruby
body: <p>I need to make an array from a string, and I have to use multiple delimiters (apart from the space):</p>
  
  <p>! @ $ # % ^ &amp; * ( ) - = _ + [ ] : ; , . / &lt; > ? \ |</p>
  
  <p>I read <a href="https://stackoverflow.com/questions/19509307/split-string-by-multiple-delimiters">here</a> and <a href="https://stackoverflow.com/questions/9375729/string-split-by-two-different-delimiters">here</a>, and the solution seems to be to use:</p>
  
  <pre><code>my_string.split(/[\s!@$#%^&amp;*()-=_+[]:;,./&lt;&gt;?\|]/)
  </code></pre>
  
  <h3>This is the exercise:</h3>
  
  <p>Given a sentence, return an array containing every other word.
  Punctuation is not part of the word unless it is a contraction.
  In order to not have to write an actual language parser, there won't be any punctuation too complex.
  There will be no " ' " that is not part of a contraction.</p>
  
  <p>Assume each of these  charactsrs are not to be considered:</p>
  
  <p>! @ $ # % ^ &amp; * ( ) - = _ + [ ] : ; , . / &lt; > ? \ |</p>
  
  <p>Examples:</p>
  
  <pre><code>alternate_words("Lorem ipsum dolor sit amet.")  # =&gt; ["Lorem", "dolor", "amet"]
  alternate_words("Can't we all get along?")      # =&gt; ["Can't", "all", "along"]
  alternate_words("Elementary, my dear Watson!")  # =&gt; ["Elementary", "dear"]
  </code></pre>
  
  <p>This is how I'm trying to do it:</p>
  
  <pre><code>def every_other_word(sentence)
    my_words = []
    words = sentence.split(/[\s!@$^&amp;*()-=_+[\]:;,.\/#%&lt;&gt;?\|]/)
    words.each_with_index do |w, i|
      next if i.odd?
      my_words &lt;&lt; w
    end
    my_words
  end
  </code></pre>
  
  <p>This is the error I get:</p>
  
  <p><code>$ ruby ./session2/3-challenge/7_array.rb
  ./session2/3-challenge/7_array.rb:14: premature end of char-class: /[\s!@$^&amp;*()-=_+[\]:;,.\/#%&lt;&gt;?\|]/
  </code></p>