只得到src值 [英] only get the src value
本文介绍了只得到src值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在数据库中有一个字段,将始终有一个标签。而且大量文字。
I have in the database a field that will always have an tag. and also lots of text..
例如:
Hey there.. whats up?
<img src="http://cdn.theatlantic.com/static/infocus/ngpc112812/s_n01_nursingm.jpg" alt="" />
.. and this is my photo!..
我需要之间仅有什么在
I need to get ONLY what between the
SRC
我想:
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;
}
不过,我已经得到了解析错误:
But I've got a parsing error :
异常详细信息:System.ArgumentException:解析\([^] +)\ /> - 引用未定义的组名IMG
Exception Details: System.ArgumentException: parsing "\([^]]+)\/>" - Reference to undefined group name img.
不知道不过,如果我的代码是在正确的道路......
dont know though if my code is the right path...
推荐答案
此问题已经在这里问。
This question has already been asked here.
string matchString = Regex.Match(original_text, "<img.+?src=[\"'](.+?)[\"'].+?>", RegexOptions.IgnoreCase).Groups[1].Value;
这篇关于只得到src值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文