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

Popular posts from this blog

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -

javascript - Using jquery append to add option values into a select element not working -

javascript - Restarting Supervisor and effect on FlaskSocketIO -