读取txt正则匹配行写入txt

StreamReader sr = new StreamReader("C:\\Users\\Administrator\\Desktop\\blogbbs\\dd.txt",Encoding.Default);

            StringBuilder sb = new StringBuilder();

            string s = "";

            string patt = "【(.+?)】";

            Regex r = new Regex(patt);

            while((s = sr.ReadLine()) != null)

            {

                if (r.IsMatch(s))

                {

                    Match m = r.Match(s);

                    sb.AppendLine(m.Groups[1].Value);

                }

            }

            File.AppendAllText("C:\\Users\\Administrator\\Desktop\\blogbbs\\123.txt",sb.ToString(),Encoding.Default);

 

你可能感兴趣的:(txt)