× {{alert.msg}} Never ask again
Get notified about new tutorials RECEIVE NEW TUTORIALS

Suppress delimiters in Ruby's String#split

Simone Carletti
Mar 21, 2015
<p>You can instruct the regexp to not capture the group using <code>?:</code>.</p> <pre><code>my_string.split(/\s?(?:\,|and)\s?/) # =&gt; ["first", "second"] </code></pre> <p>As an aside note</p> <blockquote> <p>into a database <strong>using rails</strong>.</p> </blockquote> <p>Please note this has nothing to do with Rails, that's Ruby.</p> <p>This tip was originally posted on <a href="http://stackoverflow.com/questions/26782070/Suppress%20delimiters%20in%20Ruby's%20String#split/26782205">Stack Overflow</a>.</p>
comments powered by Disqus