1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| private void ReplaceImgSrc(string content)
{
string pattern = "<img\\s+[^>]*?src\\s*=\\s*(?:(?:\"(?<url>[^\"]*)\")|(?<url>[^>]*))";
var r = new Regex(pattern, (RegexOptions.IgnoreCase | RegexOptions.Compiled));
MatchCollection results;
results = r.Matches(content);
foreach (Match mat in results)
{
Group g = mat.Groups[1];
CaptureCollection cc = g.Captures;
foreach (Capture c in cc)
{
ParseSrc(c.Value);
}
}
}
private void ParseSrc(string value)
{
if (value.Contains("TempImages"))
{
htmlRender = htmlRender.Replace(value, string.Format("http://{0}{1}", HttpContext.Current.Server.MachineName.ToLower(), value));
}
} |