You can use substring attribute selector
[att^=val]
Represents an element with the att attribute whose value begins with the prefix "val". If "val" is the empty string then the selector does not represent anything.
[att$=val]
Represents an element with the att attribute whose value ends with the suffix "val". If "val" is the empty string then the selector does not represent anything.
[att*=val]
Represents an element with the att attribute whose value contains at least one instance of the substring "val". If "val" is the empty string then the selector does not represent anything.
For your case you could use
document.querySelectorAll('[id^="demo_"]')
or
document.querySelectorAll('[id*="demo_"]')
The result would be an array of HTMLElement with id attribute whose value begins with the prefix demo_ or contains demo_ if using * instead of ^. From there you could remove each HTMLElement id att using removeAttribute() Method. More reading from here.
document.querySelectorAll('[id^="demo_"]')
.forEach(element => element.removeAttribute('id'));
htmlstr.replace(/(<[^>]+)\bid\s*=\s*"demo_[^"]+"([^>]+>)/g,'$1 $2')htmlstr.replace(/(<[^>]+)\s+id\s*=\s*"demo_[^"]+"/g, '$1'). This also works if you have attributes before theid, such as input<div data-foo="bar" id="demo_blah" class="menu">