The first answer that popped into my head was: "using querySelector method wrapped into a try - catch error handler" Something like this:
const cssString = '* > a[href *= "://adclick"]';
try {
document.querySelector(cssString);
console.log('Valid')
} catch {
console.log('Not Valid')
}
I was puzzled when I found that removing either the closing square bracket or the closing double quote the syntax was still correct (the exception is not raised). Is there a reason for this? I mean: how does the syntax be correct without one or both of the above characters? Is there an efficient and safe way to test these syntaxes?
Thanks