Gradle/Java replace text
gradle, java, regex
Solution
Assuming you just want to format `url(something)`, this should do what you want:
String regex = "url\\('([^']*?\\.(eot|ttf|fnt))(.*?)'\\)";
// font file formats^
content = content.replaceAll(regex, "url(\"#{resource['css:$1']}$3\")");
EDIT: forgot to escape some characters.
Problem
Is it possible to use regex to convert urls in css files in the way demonstrated below? I don't want to hardcode font names. from: ``` url('../fonts/glyphiconshalflings-regular.eot?#iefix') format('embedded-opentype') ``` to: ``` url("#{resource['css:../fonts/glyphiconshalflings-regular.eot']}?#iefix") format('embedded-opentype') ``` And this is what I currently have: ``` task fixCSSResources << { FileTree cssFiles = fileTree("src/main/webapp") { include "**/*.css" } cssFiles.each { File cssFile -> String content = cssFile.getText("UTF-8") // what to do here? cssFile.write(content, "UTF-8") } } ```