gpt4 book ai didi

c# - 只获取 src 值

转载 作者:行者123 更新时间:2023-11-30 13:19:41 26 4
gpt4 key购买 nike

我在数据库中有一个始终带有标签的字段。还有很多文字..

例如:

Hey there.. whats up?
<img src="http://cdn.theatlantic.com/static/infocus/ngpc112812/s_n01_nursingm.jpg" alt="" />
.. and this is my photo!..

我只需要得到

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;
}

但是我有一个解析错误:

Exception Details: System.ArgumentException: parsing "\([^]]+)\/>" - Reference to undefined group name img.

不知道我的代码是否是正确的路径...

最佳答案

这个问题已经有人问过here .

string matchString = Regex.Match(original_text, "<img.+?src=[\"'](.+?)[\"'].+?>", RegexOptions.IgnoreCase).Groups[1].Value;

关于c# - 只获取 src 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18330460/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com