When it comes to extracting critical styles from a CSS file wrapped in a @critical rule, I run into some issues:
@critical {
.foo {
...
}
@media bar {
...
}
}
The command I'm using for extraction involves sed
search and replace with the following regex (using -E flag on Mac):
sed -i '' -E 's,@critical[^{]*{\s*((.|\s)*)[^}]*},\1,g' style.css
However, while the regex itself works fine when tested on RegExr, it doesn't seem to work within the sed
command. What could be the issue here?
Thank you for your help!
—————
Edit:
Upon further research, I discovered that sed
does not support multiline regex, which explains my problem. While minifying the CSS allows the command to work, I am still looking for a solution that can handle non-minified multiline CSS files (perhaps perl? awk?).