作者jiing24 (jiing)
看板C_Sharp
标题Re: [问题] 用Regex去消除html的hyperlink
时间Sat Aug 27 09:02:08 2005
※ 引述《heliosy (这一栏是要做啥用的)》之铭言:
: 以下是我试写的简单程式码
: 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>就停止,然後再继续判断下一个吗
: 谢谢
要用不贪多比对的?
Perl 语法概念上是
$str=~ /<a href(.*?)<\/a>/g;
^^
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 59.120.12.63