Improved string regexp to not mess with matrix transposition