I have a string which contains this text:
ExtractDiv test
You can parse an HTML string with the native DOMParser:
var str = "
Then just use regular DOM methods:
console.log( doc.getElementById("main") )
Note that using a DOMParser is more efficient and safer than inserting the string somewhere in your document's innerHTML, because only the structure will be created — elements won't be executed, images won't be loaded, CSS will no try to apply to it, no rendering will occur, etc.