首页 > 代码库 > 读取txt正则匹配行写入txt

读取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);