日期:2014-05-17 浏览次数:20417 次
string tempStr = @"<a href=""xw_read129""></a>"; string pattern = @"(?i)(?<=<a[^>]*?href=(['""]?)[^'""]*?xw_read[^'""]*)(?=(['""]?)>)"; string result = Regex.Replace(tempStr, pattern, ".html");//<a href=\"xw_read123.html\"></a>
------解决方案--------------------
html=Regex.Replace(html,@"(?i)(?<=<a\b[^>]*?href=(['""]?)xw_read\d+)(?=\1[^>]*?>[^<>]*</a>",".html");
------解决方案--------------------
private string ReplaceStr(Match m) { return m.Value+".html"; } private void button10_Click(object sender, EventArgs e) { StreamReader reader = new StreamReader("c:\\1.txt"); string source = reader.ReadToEnd(); Regex reg = new Regex(@"(?is)(?<=<a\s?href[^>].*?)xw_read[\d]+"); source = reg.Replace(source, ReplaceStr); }
------解决方案--------------------
string str = "<a href=\"xwread/xw_read1213\"></a>"; string result = Regex.Replace(str, @"(?is)(?<=<a[^>]*?href=(['""\s]?).*?xw_read\d+)(?=\1)", ".html"); Console.WriteLine(result);