I need to extract a matrix from a string that looks like this (it can be a bigger matrix):
[[13,2,99][-2,3,13][1,3,0][7,77,777]]
I wanted to match all the list looking substrings with a regular expression that i tested on regexr.com that gave me the matches i wanted but not on pythex.org or in my script
Here is a sample code that uses the regex:
import numpy as np
import re
matrix = "[[13,2,99][-2,3,13][1,3,0][7,77,777]]"
l = []
regex = re.compile(r"\[(-?[0-9]+,)+-?[0-9]+]")
for el in re.findall(regex, matrix):
l.append(np.fromstring(el[1:len(el)-1], dtype=int, sep=",").tolist())
a = np.array(l)