Text in the IMG tag:
Regular expression matching an IMG tag: string Pattern = @ "]*/s*src/s*=/s* ([']?) (? <url>/s+) '? [^>]*> ";
Regular expression that matches the src of img: string Pattern = @ "(? <=src/s*=/s*[/'/" "]?) (? <url>[http/:////]? [^'""]+)";
Matching results: http://www.mycreative.com.cn/upload/2010/4/tiancheng2.jpg
Get the SRC address of img in text:
String Pattern = @ "(? <=src/s*=/s*[/'/" "]?) (? <url>[http/:////]? [^'""]+)";
Regex reg = new Regex (Pattern, regexoptions.ignorecase);
MatchCollection Colmatch = Reg. Matches (text);
StringBuilder strimage = new StringBuilder ();
if (Colmatch.count > 0)
{
foreach (Match m in Colmatch)
{
Strimage.append (M.value). Append (', ');
}
}
Match the text of the IMG and add a link to the IMG tag
String Pattern = @ "]*/s*src/s*=/s* ([']?) (? <url>/s+) '? [^>]*> ";
Regex reg = new Regex (Pattern, regexoptions.ignorecase);
MatchEvaluator myevaluator=new MatchEvaluator (Repleacereg);
String content = Reg. Replace (text), myevaluator);
Repleacereg function:
private String Repleacereg (Match m)
{
String result=m.tostring ();
if (albumid! =-1)
{
result= "<a href=ImageShow.aspx?albumid= "+ albumID +" > "+ M +" </a> ";
}
return result;
}