const regex = /#(?!:[\w]+)(?=([\w\d\[\]\,\*\=\>\.\s]*[\{\,\[]+))/g;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('#(?!:[\\w]+)(?=([\\w\\d\\[\\]\\,\\*\\=\\>\\.\\s]*[\\{\\,\\[]+))', 'g')
const str = `div#xyz, #xyz, div#xyz[id='xyz'],
.def>#xyz, .def>div#xyz, .def>#xyz,
.def>div#xyz[id=*]{
color:#ee2ee2;
}
@media (min-width: 30em) and (orientation: landscape)
{
.abc{
background-color :#FFFFFF;
border-color:1px solid #eee ;
}
.def>#xyz, .def #xyz, .def>#xyz{border-color:1px solid #ddd;}
}`;
const subst = `.`;
// The substituted value will be contained in the result variable
const result = str.replace(regex, subst);
console.log('Substitution result: ', result);
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions