有如下需求:
对于一段字符串内容,如:
@font-face {
font-family: UKK_Basma;
font-style: normal;
font-weight: normal;
src: url("ZNJK_Basma.ttf");
}
@font-face {
font-family: UKK_Basma;
font-style: normal;
font-weight: normal;
src: url("UKK_Basma.ttf");
}
@font-face {
font-family: UKK_Basma;
font-style: normal;
font-weight: normal;
src: url("UKK_BasmaB.ttf");
}把红色部分全部替换成一个统一的字符串,如src: url("myfont.ttf");大致了解可以用通配符,但是没有学习过,望大虾指导
对于一段字符串内容,如:
@font-face {
font-family: UKK_Basma;
font-style: normal;
font-weight: normal;
src: url("ZNJK_Basma.ttf");
}
@font-face {
font-family: UKK_Basma;
font-style: normal;
font-weight: normal;
src: url("UKK_Basma.ttf");
}
@font-face {
font-family: UKK_Basma;
font-style: normal;
font-weight: normal;
src: url("UKK_BasmaB.ttf");
}把红色部分全部替换成一个统一的字符串,如src: url("myfont.ttf");大致了解可以用通配符,但是没有学习过,望大虾指导
public static void main(String[] args) {
String text = "@font-face {" + "font-family: UKK_Basma;"
+ "font-style: normal;" + "font-weight: normal;"
+ "src: url(\"ZNJK_Basma.ttf\");" + "}";
text = text.replaceAll("src: url(.+);", "src: url(\"myfont.ttf\");");
System.out.println(text); }
}
还是单纯的一个字符串,
文件就逐行读取,循环替换,
单独的就把ls的text换成你自己的不就行了?
String s = "SRC : url ( \"ZNJK_Basma.ttf\");";
s = s.replaceAll("((?i)src\\s*:\\s*(?i)url)\\s*\\(.+?\\);", "$1(\"myfont.ttf\");");
System.out.println(s);
}