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

IF statement in MySQL trigger -

c++ - What does MSC in "// appease MSC" comments mean? -

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