I'm trying to replace all class names in a CSS file. I am using JavaScript/Node.js.
My current solution is this: /\.[a-z][a-z0-9-_]*/g
.
At the end of the file is a comment that references the source map file: /*# sourceMappingURL=style.css.map */
. Now the file extensions of that URL also get replaced.
Given the following input:
.text-center { text-align: center; }
table.simple{background:#fff;}.bg-white{background:#fff;}
/*# sourceMappingURL=style.css.map */
/*
Example comment file.css
*/
the result is:
.a { text-align: center; }
table.a{background:#fff;}.a{background:#fff;}
/*# sourceMappingURL=style.a.a */
/*
Example comment file.a
*/
what I want is:
.a { text-align: center; }
table.a{background:#fff;}.a{background:#fff;}
/*# sourceMappingURL=style.css.map */
/*
Example comment file.css
*/
How do I have to change my RegEx so it does only match class names, that are outside of comments (//
comments are not relevant here)?