Value of element by id from variable

To get value of element by id from document is very easy:
var example = document.getElementById(‘myId’);

But what if I would like to get value by id from variable:
var example1 = ‘<a href=“example.html” id=“myId”>lorem ipsum</a>’

Is there any way?

Do you mean for instance the lorem ipsum text?

no and I am sorry, I didn’t give good example. This one is better:

var example1 ='<div><span>sdf</span><a href="example.html" id="myId">lorem ipsum</a></div>'

So how to get element by id from this variable to alert “<a href=“example.html” id=“myId”>lorem ipsum</a>”

A regular expression would be needed to grab the id of the element, I’m not too good with them but there may be another user here that knows a pre-designed expression for this type of search.