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?
You can do it with this simple regular expression:
"hello+world-apple+francisco-rome".scan(/[+\-]?\w+/)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With