var template = "somthing text [attr1], [attr2]"; var regexp = /\[(\w+)\]/gi; var arr = []; var match; while (match = regexp.exec(template)) { arr.push(match[1]) } alert(arr);