I'm trying to match all the CSS selectors and directives below excluding any comments and any media queries.
a {color: red !important;}
#p1 {
margin-top: 20px !important
}
/* Client-specific styles */
.ExternalClass,
.ExternalClass p,
.ExternalClass span,
.ExternalClass font,
.ExternalClass td,
.ExternalClass div {
line-height: 100%;
}
a {}
@media query {
a { display:none }
}
I've come up with the following RegEx: [a-zA-Z#.:*]{1}[^\/*]+?{[\s\S]*?}. This matches everything correctly but includes the @media query. I've tried using a negative lookahead e.g. (?!.+@media.+) but that didn't help.
What can I do to extract only the selectors/directives?
Example: https://regex101.com/r/JmjthP/3
Solution
With help from @Wiktor Stribiżew the working solution was this:
/^(?!.*@media)[\t ]*([a-zA-Z#.:*\[][^{\/]*\s*){[\s\S]*?}/