Q:

Python3 - Extracting data from a user inputted string. Could be in the wrong format

I've been trying to find a way of taking a user input which should be in the form:
[x1,y1][x2,y2]
This whereby x1, x2, y1, y2 are integer values.
The point is in making a chess piece move from position a to position b
My aim is to have the user input it as so:
move = input("\nSyntax: '[x,y][x,y]'")

My intent is to break apart the string so that I end up with two lists.
From = [x1,y1]
To = [x2,y2]
The nearest thing I found was: Extract the data specified in brackets '[ ]' from a string message in python.
However, for such a simple string in my case, I'm sure there's an easier way - what's most efficient. Also, in this case, the user may make a typo etc... How would I make sure it's in the format [x1,y1][x2,y2]?

A:

Let's say your input string is like:
my_str =  '[x1,y1][x2,y2]'

For storing the values in separate variables, you may strip the [ and ] from the corners and replace ][ with ,. Then split the string on , as:
x1, y1, x2, y2 = my_str.strip('[]').replace('][', ',').split(',')

The values hold by x1, y1, x2, y2 will be:
>>> x1, y1, x2, y2
('x1', 'y1', 'x2', 'y2')

Then for storing the values to list, you may do:
from_list = [x1, y2]
to_list = [x2, y2]

If you are ok with changing the format of input string from [x1,y1][x2,y2] to [x1,y1],[x2,y2] (comma between ][), then you may use ast.literal_eval as:
>>> from ast import literal_eval
>>> my_str =  '[1,2],[3,4]'

>>> from_list, to_list = literal_eval(my_str)

