ruby - Lossy Split and Join Expression -
i'm using split(/ /) method, after join them ending white spaces gone.
the string matched against this:
"word word word " the array returned split(/ /) this:
["word", " ", "word", " ", " ", "word"] i expected this:
["word", " ", "word", " ", " ", "word", " ", " "]
this should work you
str.scan(/\w+| /) this example
2.2.1 :003 > "word word word ".scan(/\w+| /)
=> ["word", " ", "word", " ", " ", "word", " "]
Comments
Post a Comment