One possible approach is to create an element from that string, then query against it:
var str = '<select name="random[]" class="myclass" id="x">'
+ '<option>hello</option>'
+ '</select>';
var d = document.createElement('div');
d.innerHTML = str;
var id = d.querySelector('select').id; // getting the id
d.querySelector('select').id = 'new_x'; // replacing it
str = d.innerHTML; // getting the updated string back
I assumed here it's always will be a <SELECT>
element which id should be fetched, but you can use whichever selector suits you best. The real point of this approach is creating a temporary DOMElement to use its methods for fetching various attributes and/or nested elements from a HTML string.