Created
April 21, 2020 07:37
-
-
Save Hibrix-net/70639ef032e7dd77e2e6fb2c60064a6e to your computer and use it in GitHub Desktop.
Regex to match CSS rules and media queries
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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