Reputation: 32992
I want to split the string "hello+world-apple+francisco-rome"
, into ["hello", "+world", "-apple", "+francisco", "-rome"]
.
String::split
actually loses the splitting element. Anyone can do that?
Upvotes: 3
Views: 555
Reputation: 13438
You can do it with this simple regular expression:
"hello+world-apple+francisco-rome".scan(/[+\-]?\w+/)
Upvotes: 4