我在數據庫中有一個總是有標籤的字段。也有很多的文字..只得到src值
例如:
Hey there.. whats up?
<img src="http://cdn.theatlantic.com/static/infocus/ngpc112812/s_n01_nursingm.jpg" alt="" />
.. and this is my photo!..
我需要得到
SRC之間ONLY什麼
我想:
public string LinkPicCorrect(string path)
{
//string input = "[img]http://imagesource.com[/img]";
string pattern = @"\<img>([^\]]+)\\/>";
string result = Regex.Replace(path, pattern, m =>
{
var url = m.Groups[1].Value;
// do something with url here
// return the replace value
return @"<img src=""" + url + @""" border=""0"" />";
},
RegexOptions.IgnoreCase);
result = "<img src='" + result + "'/>";
return result;
}
但我有一個解析錯誤:
異常詳細信息:System.ArgumentException:解析 「\([^] +)\ />」 - 引用未定義的組名IMG。
雖然不知道是否我的代碼是在正確的道路......
謝謝你,幫助了很多。 – thormayer
如果有後SRC,沒有道具,你必須添加像ALT」之源後,這是行不通的。替換‘’與‘’ –