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 split
ting 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
Post a Comment