提取以特定的字符串开头和结尾的正则表达式

今天试着写了一下以特定的字符串开头和结尾的正则表达式

来替换文本中的内容居然成功了,分享一下。


package com.test.mytest.study;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
 
public class Demo001 {
 
    public static void writeFile(String strSrc) {
        FileWriter writer = null;
        FileReader reader = null;
        BufferedReader br = null;
        BufferedWriter bw = null;
 
        try {
          
            reader = new FileReader(strSrc);
            File filestrSrc = new File(strSrc);
            String str = null;
 
            br = new BufferedReader(reader);
 
         
            StringBuffer sb = new StringBuffer("");
            while ((str = br.readLine()) != null) {
                String a=   str.replaceAll(".ff(.*)}", "");
             a=a.replaceAll("\\@font-face\\{font-family", "");
//空行不读入新文件里面。
 if(!"".equals(a)){
                     sb.append(a + "\n");
                }
               
            }
            filestrSrc.delete();
            File file = new File(strSrc);
            if (!file.exists()) {
                file.createNewFile();
            }
             
            // 这里的true,是以追加的方式写
            writer = new FileWriter(strSrc, true);
            bw = new BufferedWriter(writer);
            bw.write(sb.toString());
            br.close();
            reader.close();
 
            bw.close();
            writer.close();
 
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
 
    public static void main(String[] args) {
        Demo001.writeFile("/home/xueqy/html.css");
    }
}


你可能感兴趣的:(正则表达式)