var str = 'object[2]'; var search = str.match(/(object)\[(.*)\]/); var result = search[1] + search[2]; alert(result);