Q:

sort function problem with strings containing square brackets

As shown below, when string contains a square bracket, sorted array is not in a correct ascending order.  Is there a way to work around this problem? 
BAD
Input:
 A = {'[Test2]','[Test]','[Test1]'}
 sort(A)

Output:
'[Test1]'    '[Test2]'    '[Test]'

GOOD
Input:
A = {'Test2','Test','Test1'}
sort(A)

Output:
'Test'    'Test1'    'Test2'

A:

As the comment explained, the result is expected, since 1 or 2 is before ]:
sort(']1')
ans =
'1]'

If you want to ignore the brackets in cell elements, you can do 
A1 = regexprep(A, ']$', ''); % remove ending ']'
[~, ind] = sort(A1);
A_sorted = A(ind);

