0
我有一个HTML
字符串,其中包含一些img
标签。我必须在每个img
标记中查找并修改src
属性。例如正则表达式:查找并修改多个匹配
原来的标签是:
<img src="http://some.domain.com/images/uncat-images/?file=vx1qro62da5th39u.jpeg&dimension=50" style="color:#2345f1" />
我想要得到的file
查询字符串的值,在一些代码映射它,得到了新的名字,并用新的修改整个src
属性。
例如在给出的例子中,file
的名字是vx1qro62da5th39u.jpeg
。所以,我希望它从地图中找到新的值。例如,它将是newfilename.png
。现在我想更换整个src
值与此:
/newroot/images/newfilename.png
这意味着要img
应该是这样的:
<img src="/newroot/images/newfilename.png" style="color:#2345f1" />
我有这个Regex
,给了我一个名为组src
值:
var regex = new Regex("<img.+?src=[\\\"'](?<URL>.+?)[\\\"'].*?>", RegexOptions.Compiled | RegexOptions.IgnoreCase);
说实话,我被堵在这里约2小时):
var regex = new Regex("<img.+?src=[\\\"'](?<URL>.+?)[\\\"'].*?>", RegexOptions.Compiled | RegexOptions.IgnoreCase);
var html = "My html string with several img tags...";
var matches = regex.Matches(html);
foreach (Match match in matches){
// I'm right here):
}
有没有人知道如何继续?提前致谢。
**谢谢你**正常工作 –