Why is it that when I run the following in the python interpreter
re.findall(r'^-?[0-9]+$', "[50, 4]")
I get [] as the result? If I'm not mistaken this should return [50, 4].
You are using ^...$. They mean the beginning and the ending of the string. So, you are actually trying to find out if the entire string (from the starting till the ending) is full of numbers. Just drop them and you will get what you wanted
>>> re.findall(r'-?[0-9]+', "[50, 4, -123]")
['50', '4', '-123']
If you want to convert all of them to actual numbers, then apply int function with a list comprehension, like this
>>> [int(num) for num in re.findall(r'-?[0-9]+', "[50, 4, -123]")]
[50, 4, -123]
ast.literal_eval("[50, 4]")?