A single lookahead should do the trick here:
a = "this is [test] line i [want] text [inside] square [brackets]"
words = a.match(/[^[\]]+(?=])/g)
but in a general case, exec
or replace
-based loops lead to simpler code:
words = []
a.replace(/\[(.+?)\]/g, function($0, $1) { words.push($1) })