I am trying to parse a media query with Javascript.
I intend the mark-up string to look like this
@media not screen and (min-width: 700px) {
padding-left: 30px;
background: url(email-icon.png) left center no-repeat;
}
@media (max-width: 600px) {
color: red;
}
Will an output:
@media not screen and (min-width: 700px) {
.foo{
padding-left: 30px;
background: url(email-icon.png) left center no-repeat;
}
}
@media (max-width: 600px) {
.foo{
color: red;
}
}
So far I have this
const css = `@media (max-width: 600px) { color: red; }`
const pattern = new RegExp('@media[^{]+([\s\S]+})\s*')
const cssnew = css.replace( pattern, (full,match) => `{ .foo${match}}` );
// cssnew === "@media (max-width: 600px) { .foo{ color: red; } }"
This Regex look like it working for 1(@media
) https://regex101.com/r/r0sWeu/1
and thats ok... but the replace function is not getting called?
Thanks for an help