I want to split the string with spaces,, and ' with a single ruby โโcommand.
'
word.split will be separated by spaces;
word.split
word.split(",") will be broken into word.split(",")
word.split(",")
word.split("\'") will split into ' .
word.split("\'")
How to do all three at the same time?
word = "Now is the,time for'all good people" word.split(/[\s,']/) => ["Now", "is", "the", "time", "for", "all", "good", "people"]
Regex.
"a,b'c d".split /\s|'|,/ # => ["a", "b", "c", "d"]
Here is another one:
word = "Now is the,time for'all good people" word.scan(/\w+/) # => ["Now", "is", "the", "time", "for", "all", "good", "people"]
x = "one,two, three four" new_array = x.gsub(/,|'/, " ").split