0
votes

I want to find a regular expression in order to check if the string given is a matrix. The matrix in the Giac library is defined like

[[1,2,3],[4,5,6],[7,8,9]]

Starts with "[", ends with "]" and every row (vector) is separated by "," Vectors are defined in a similar way: [1,2,3] So, a matrix is like a vector of vectors.

I have created a regular expression

NSString *pattern = @"\\[(\\[-?([0123456789]+(\\.[0123456789]+)?,)+-?[0123456789]+(\\.[0123456789]+)?])+,\\[-?([0123456789]+(\\.[0123456789]+)?,)+-?[0123456789]+(\\.[0123456789]+)?]]";

but i cannot find how to check that every vector (row) has the same number of elements...

For example, a string like "[[1,2],[3,4,5],[6,7,8,9,0]]" matches with the regular expression but it's not a matrix...

Any help?

1

1 Answers

0
votes

As i was told by a professor of mine, this cannot be done, because it is NOT a regular language so it cannot be described by a regular expression...