Trying to split string into single words or "quoted words", and want to keep the quotes in the resulting array

Viewed 4247

I'm trying to split a string like Presentation about "Test Driven Development" into an array like this:

[ 'Presentation',
  'about',
  '"Behavior Driven Development"' ]

I have tried CSV::parse_line(string, col_sep: ' '), but this results in

[ 'Presentation',
  'about',
  'Behavior Driven Development' ] # I'm missing the quotes here

I also tried some regexp magic, but I'm still a beginner and didn't succeed. I guess this is quite simple for a pro, so maybe someone could point me into the right direction? Thanks.

3 Answers
Related