tags:

views:

136

answers:

2

I have a string:

"hello\t    World\nbla"

I would like to split it to:

["hello\t    ",
"World\n", 
"bla"]

How would I do this in Ruby?

+2  A: 

Hopefully this helps..

>> "hello\t   World\nbla".scan(/\w+\s*/)
=> ["hello\t   ", "World\n", "bla"]
dylanfm
Much prettier than my hackyiness :p
Sam Saffron
\w will be a bit funny about hyphenated words, for example
Gareth
+7  A: 
>> "hello\t    World\nbla".scan /\S+\s*/
=> ["hello\t    ", "World\n", "bla"]
Gareth
yerp, I think \S+ should be a bit more correct than \w+
Sam Saffron