ruby on rails - Excluding quotes in a split method Regex -


i'm having hard time understanding how use regexp in split method in ruby.

i have string:

"mark sally 'john smith' steve" 

and trying array:

 ["mark", "sally", "john smith", "steve"] 

instead of splitting string, consider matching or using parser this.

s = "mark sally 'john smith' steve" p s.scan(/'([^']+)'|(\s+)/).flatten.compact #=> ["mark", "sally", "john smith", "steve"] 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -