In the project that I am currently working on, various encoders from different walks of life were visible. After successfully writing a clean Capistrano recipe to minimize css and js files, I ask myself how to recognize the various url patterns spread around our CSS code base to rewrite them all right away before they start living. The patterns I'm looking for are
url('../../images/ url(../images/ url("../../../images/ url(images/
So basically, here is an input example:
.test{background:url('/images/test.jpg') no-repeat top left}.pouet{background:url("../../images/bg.png")}
Please note that in some cases we have quotation marks, in others not ... And what I'm trying to get
.test{background:url('http://www.cdnImages.com/images/test.jpg') no-repeat top left}.pouet{background:url("http://www.cdnImages.com/images/bg.png")}
All this should be replaced with my cdn url. The most mysterious thing is how to do it so as not to make mistakes.
I came up with a regex that fits my needs: rubular permalink
I watched the sed command using it as follows
sed '/url([^\/](.*?)images/http:\/\/www.cdnImages.com' myFile.css
but that doesn't seem to do the job.
My current research has led me to this.
find
and while the regex is perfect for the need (check here to see the output drawn , somewhere there is something wrong.
Any idea? Thank you very much.
source share