2013-08-09 8 views
3

아래와 같이 CSS 파일의 URL을 변환 할 때 regex를 사용할 수 있습니까? 나는 글꼴 이름을 하드 코드하고 싶지 않다.Gradle/Java 대체 텍스트

에서 :

url("#{resource['css:../fonts/glyphiconshalflings-regular.eot']}?#iefix") format('embedded-opentype') 

그리고 이것은 내가 현재 가지고있는 것입니다 :

url('../fonts/glyphiconshalflings-regular.eot?#iefix') format('embedded-opentype') 

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") 
    } 
} 
+0

텍스트의 패턴은 무엇입니까? 항상 'URL (무언가) 형식 (무언가)'이 될 것입니까? –

+0

@SongCGGao here 's example http://pastebin.com/VzmaFrMJ – perak

답변

5

그냥 url(something)를 포맷 할 가정이 무엇을해야하는지 당신 원하는 :

String regex = "url\\('([^']*?\\.(eot|ttf|fnt))(.*?)'\\)"; 
//     font file formats^   
content = content.replaceAll(regex, "url(\"#{resource['css:$1']}$3\")"); 

편집 : 일부 문자를 이스케이프하는 것을 잊었습니다.

+1

여기서 파일을 어디에 지정하고 있습니까? –