有如下需求:
对于一段字符串内容,如:
  @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");大致了解可以用通配符,但是没有学习过,望大虾指导

解决方案 »

  1.   

    public class Test {
    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); }
    }
      

  2.   

    你这字符串是存在文件里的,
    还是单纯的一个字符串,
    文件就逐行读取,循环替换,
    单独的就把ls的text换成你自己的不就行了?
      

  3.   

    正则表达式替换所有就行了 public static void main(String[] args) throws Exception {
    String s = "SRC : url ( \"ZNJK_Basma.ttf\");";
    s = s.replaceAll("((?i)src\\s*:\\s*(?i)url)\\s*\\(.+?\\);", "$1(\"myfont.ttf\");");
    System.out.println(s);
    }
      

  4.   

    擦,出bug了,楼主结帖率超过100%!