I was trying to write a regular expression to look for the following conditions and am having trouble understanding how to do it. It's for reading an INI file. I know there is code out there to do this but would like to understand how to do it myself.

Here are the conditions for one line read from a text file:

1. contains one and only one '[' AND one and only one ']'
2. returns the data between the brackets
3. provides some information that allows me to trap an error if it's not a properly formatted section heading. ([[text], text], etc)

Here's what I was trying to use "\[\(.*\)\]" with regex.matches.