My string is
"[1,2,3]"
I want to get output in the below format
[1,2,3]
I want to extract array present in my string.
You can use eval:
try:
eval("[1,2,3]")
=> [1, 2, 3]
eval without warning about the risks.Ok, try it:
"[1,2,3]".scan(/\w/).map{|x| x.to_i}