See the documentation:
and all in all it takes any number or any character until a square bracket appears and stores it in $1 and then it addresses everything following the square bracket. And then it returns the value stored in $1.
See also here for other solutions: