Javascript - return string between square brackets

Since javascript doesn't support captures, you have to hack around it. Consider this alternative which takes the opposite approach. Rather that capture what is inside the brackets, remove what's outside of them. Since there will only ever be one set of brackets, it should work just fine. I usually use this technique for stripping leading and trailing whitespace.

mystring.replace( /(^.*\[|\].*$)/g, '' );

Use grouping. I've added a ? to make the matching "ungreedy", as this is probably what you want.

var matches = mystring.match(/\[(.*?)\]/);

if (matches) {
    var submatch = matches[1];
}