I need to split a string without removing the separators. Is there a simple and "Ruby oriented" way to do this?
For example, given a string like this:
str = "(This is (a test))"
what I need is this:
["(", "This", "is", "(", "a", "test", ")", ")"]
I tried using the split method for strings, using the brackets "("
and ")"
as separators, but then I get them removed from the returning array. Any advice will be helpful.
Maybe something like this:
str.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