111,076
社区成员




static void Main(string[] args)
{
string str=@"<img height=""469"" width=""452"" alt="""" src=""/UploadFile/FCKeditor/image/123.jpg"" /> ";
Regex re = new Regex(@"<img[^(src)]*src=""(?<src>[^""]*)""");
Console.WriteLine(re.Match(str).Groups["src"].Value);
}
<img\s[^(src)]*\s*src="([^"]*)" />
//这样稍微好点,还可以匹配只有src属性的情况。
<img\s[^(src)]*\ssrc="([^"]*)" />
B = Regex.Match(nr, "<img[^>]*src=[\"']*([^>\"']+)[\"']*\\s*/>").Groups[1].Value;
/// <summary>
/// 获得图片的路径并存放
/// </summary>
/// <param name="M_Content">要检索的内容</param>
/// <returns>IList</returns>
public static IList<string> GetPicPath(string M_Content)
{
IList<string> im = new List<string>();//定义一个泛型字符类
Regex reg = new Regex(@"<img.*?src=""(?<src>[^""]*)""[^>]*>", RegexOptions.IgnoreCase);
MatchCollection mc = reg.Matches(M_Content); //设定要查找的字符串
foreach(Match m in mc)
{
im.Add(m.Groups["src"].Value);
}
return im;
}
@"<img\s(?:(?!src)[^<>])*src=""([^""]*)""/>"
string input = @"<img height=""469"" width=""452"" alt="""" src=""/UploadFile/FCKeditor/image/123.jpg"" /> ";
Match m = Regex.Match(input, @"(?i)(?<=<img\b[^<>]*src\s*=\s*[""])[^""]*");
string b = m.Value;