Click here to Skip to main content
15,895,871 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Expert,

In asp .net there is one string , from which i have to capture src value from image tag, and the string is in valid html format.

Please suggest me reguler expression or method for this.

please help me.

Thanks in advance.
Posted
Updated 9-Apr-12 18:52pm
v2
Comments
Nilesh Patil Kolhapur 10-Apr-12 0:09am    
give ur code what u try
udusat13 10-Apr-12 0:28am    
Please check my code,

i am reading xml like following

XDocument doc = XDocument.Load("http://news.google.com/news?pz=1&cf=i&ned=us&hl=en&topic=e&output=rss");

now from this xml i have to fetch image src value, to display those all image.

these are dynamic news section.
Please help me.

The following code can be used to match all img src in the source text and to populate list with value of src attribute.
C#
string sourceText; 
var imgSrcMatches = System.Text.RegularExpressions.Regex.Matches(sourceText,
            string.Format(@"<\s*img\s*src\s*=\s*{0}\s*([^{0}]+)\s*{0}","\""),
            RegexOptions.CultureInvariant | RegexOptions.IgnoreCase | 
            RegexOptions.Multiline);
List<string> imgSrcs = new List<string>();
foreach(Match match in imgSrcMatches)
    imgSrcs.Add(match.Groups[1].Value);
 
Share this answer
 
if you provide id for that image tag you can easily get the src value using javascript
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900