only get the src value

asp.net, c#

Solution

This question has already been asked here.

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

Problem

I have in the database a field that will always have an tag. and also lots of text.. For example: ``` Hey there.. whats up? <img src="http://cdn.theatlantic.com/static/infocus/ngpc112812/s_n01_nursingm.jpg" alt="" /> .. and this is my photo!.. ``` I need to get ONLY what between the src I tried : ``` 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; } ``` But I've got a parsing error : Exception Details: System.ArgumentException: parsing "\([^]]+)\/>" - Reference to undefined group name img. dont know though if my code is the right path...

Original source

Related problems