java使用正则表达式将xml文本中的特定的标签替换掉

import java.io.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/*
*
* 使用正则表达式将文本中的 
    替换成空字符串 ,复制他人博客, * 有时候代码块前面的序号会在代码下面,将ul替换,就不会显示序号 * */ public class Main2 { static File file2 = new File("E:/paper/blog0.xml");//Persons.xml文件绝对路径 static File file3 = new File("E:/paper/blog1.xml");//Persons.xml文件绝对路径 public static void main(String[] args) throws Exception { BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file2))); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file3))); String tmpStr=""; String regStr = "
      (.*)
    "; Pattern pattern = Pattern.compile(regStr); while((tmpStr=reader.readLine())!=null){ Matcher m = pattern.matcher(tmpStr); if (m.find()) { String strFind = m.group(0); tmpStr = tmpStr.replace(strFind, ""); } writer.write(tmpStr); } writer.flush(); reader.close(); writer.close(); } }

     

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