Skip to content

Instantly share code, notes, and snippets.

@Hibrix-net
Created April 21, 2020 07:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Hibrix-net/70639ef032e7dd77e2e6fb2c60064a6e to your computer and use it in GitHub Desktop.
Save Hibrix-net/70639ef032e7dd77e2e6fb2c60064a6e to your computer and use it in GitHub Desktop.
Regex to match CSS rules and media queries
// Source: https://stackoverflow.com/questions/36910664/recursive-subroutine-regex-to-match-css-media-queries#answer-36911319
@media print\b[^{]*({((?:[^{}]+|(?1))*)})
// to match i.e.:
@media print {
.post {
margin: 6.6rem 0px 8.8rem;
padding-bottom: 2.2rem;
border-bottom: #eaecee
}
}
// To match any simple rule
.ctrl \{[^}]*\}
// to match i.e.:
.ctrl {
background: 0px -220px repeat scroll rgba(0, 0, 0, 0.3);
width: 100%;
height: 40px;
bottom: 0;
left: 0;
position: absolute
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment