[問題] 用Regex去消除html的hyperlink

看板C_Sharp (C#)作者 (這一欄是要做啥用的)時間20年前 (2005/08/24 16:43), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/2 (看更多)
以下是我試寫的簡單程式碼 Regex re = new Regex("<a href=.*\">"); StreamReader sr = new StreamReader("a.htm"); string line = null; string all = null; while((line = sr.ReadLine()) != null) { if(line.IndexOf("<a href=") != -1) { all += re.Replace(line,"").Replace("</a>","") + "\r\n"; } else { all += line + "\r\n"; } } sr.Close(); StreamWriter sw = new StreamWriter("b.htm"); sw.Write(all); sw.Flush(); sw.Close(); 但是這樣如果遇到一行中有兩個hyperlink的話 就會把第一個hyperlink全都刪掉了 有什麼判斷方式可以讓他遇到第一個</a>就停止,然後再繼續判斷下一個嗎 謝謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.109.42.171
文章代碼(AID): #1333C-IA (C_Sharp)
文章代碼(AID): #1333C-IA (C_Sharp)