Skip to content

Instantly share code, notes, and snippets.

@tjstebbing
Created August 15, 2017 05:52
Show Gist options
  • Save tjstebbing/135cfc906340fe3dff02ba68fb16451c to your computer and use it in GitHub Desktop.
Save tjstebbing/135cfc906340fe3dff02ba68fb16451c to your computer and use it in GitHub Desktop.
#javascript #css #regex
const reg = /\s*([^\s\{,]+(?:\s+[^\s\{,]+)*)|\s*\{[^\}]*\}/gm
css = `
.car, div.train, #bus
div.jetski:nth-child(4n)!important {
display: none;
}
.banana ,
#fruit.ap_ple.pear {
color: red;
}
ul>li:nth-child input[type=text] {
border-width: 1px;
}
`
console.log(getMatches(reg, css))
function getMatches(re, str) {
var out = []
var match
while ((match = re.exec(css)) !== null) {
if (match[1]) out.push(match[1])
}
return out
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment