Question: I am having string:

```
str = "[[591, 184] , [741, 910] , [987,512], [2974, 174]]"

```

I want to convert this to an array:

```
arr = [[591, 184] , [741, 910] , [987,512], [2974, 174]]

```

How can i do this?

Answer: 
A JSON parser ought to work fine:

```
require "json"

str = "[[591, 184] , [741, 910] , [987,512], [2974, 174]]"
p JSON.parse(str)
# => [[591, 184], [741, 910], [987,512], [2974, 174]]

```

Try it on eval.in: <https://eval.in/777054>
One way to do this:

```
str = "[[591, 184] , [741, 910] , [987,512], [2974, 174]]"
reg = /(?<=\[)[\d,?\s?]+(?=\])/
str.scan(reg).map { |s| s.scan(/\d+/).map(&:to_i) }
#=> [[591, 184], [741, 910], [987, 512], [2974, 174]]

```

or taking a leaf out of @Jordan's book, but using YAML:

```
require 'yaml'
str = "[[591, 184] , [741, 910] , [987,512], [2974, 174]]"
YAML.load(str) #=> [[591, 184], [741, 910], [987, 512], [2974, 174]]

```