//例如我想把如下格式记录中的NAME值修改为WANG string line = "ADDR=1234;NAME=ZHANG;PHONE=6789"; Regex reg = new Regex("NAME=(.+);"); string modified = reg.Replace(line, "NAME=WANG;"); //修改后的字符串为 ADDR=1234;NAME=WANG;PHONE=6789
//例如我想提取记录中的NAME值 string line = "ADDR=1234;NAME=ZHANG;PHONE=6789"; Regex reg = new Regex("NAME=(.+);"); Match match = reg.Match(line); string value = match.Groups[1].Value; Console.WriteLine("value的值为:{0}", value);
string html = "<ol><li>发顺丰</li><li>灌灌灌</li></ol><div style=\"text-align: center;\"><img src=\"data: image/jpeg; base64,/9j/4QAYRXhpZgAASUkqAAEQf//Z\"><br></div>"; Regex myreg = new Regex("base64,(.+)\""); Match myMatch = myreg.Match(html); string aaa = myMatch.Groups[1].Value; string bbb = myreg.Replace(html, "base64,http://www.66kangba.com\"");
过滤特殊字符
string result = Regex.Replace(search.Trim(), @"\W", "");