Compute the specificity of a CSS selector
Javascript ES6 453 430 bytes
Here goes my shot!
a=&gt;(s){var n=z=[],c=[0,0,0,0],e=s.split(/[\s\+\&gt;\~]+/);return e.forEach((s)=&gt;{n=n.concat(s.replace(/\((.*)\)/,&quot;&quot;).split(/(?=\[|::|\.)/))}),n.forEach((s)=&gt;{if(0==s.indexOf(&quot;::&quot;))return z.push(s);var n=s.split(/(?=:)/);z=z.concat(n[0].split(/(?=[\#])/)),/before|after/.test(n[1])?z.push(&quot;:&quot;+n[1]):n[1]&amp;&amp;z.push(n[1])}),z.forEach((s)=&gt;{/^[a-z]+$/gi.test(s)||&quot;::&quot;==s[0]+s[1]?c[3]++:-1!=&quot;:.[&quot;.indexOf(s[0])?c[2]++:&quot;#&quot;==s[0]&amp;&amp;c[1]++}),c}

@UPDATE improved code, now it handles :not and :before/:after selectors better, nevertheless haven't tested CSS escape sequences.