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

Can u tell me regular expression to split image src

For example string is like below

C#
string testing="<img src=\"cid:tmpImage.gif\">,cdefetfdgfdg ,ewrewrewr,<img src=\"cid:tmpImage1.gif\">,<img src=\"cid:tmpImage2.gif\">,<img src=\"cid:tmpImage3.gif\">,<img src=\"cid:tmpImage4.gif\">";
    string[] splitText = Regex.Split(testing, @"(<img([^>]+)>)");



after split I need in the following form


src='images/img1.jpg'
src='images/img2.jpg'
src='images/img3.jpg'
src='images/img4.jpg'


Thanks
Posted
Comments
Sergey Alexandrovich Kryukov 7-Nov-12 2:02am    
Why?
--SA
MT_ 7-Nov-12 2:13am    
I can't find any text like images/img1.jpg in the input ! All are gif. You mean you want to find src = cid:tmpImage.gif etc ?
Code_seeker_ 7-Nov-12 2:15am    
yes
MT_ 7-Nov-12 8:04am    
Did the solution below helped?

Many things can be found with Regex, but in this case some HTML parser could do better. It's very easy if this HTML is well-formed XML, as XML parsers (at least three of them) are readily available in .NET. If the HTML is not well-formed, it's much worse, but you can use some available HTML parser which can deal with that. Try this one:
http://www.majestic12.co.uk/projects/html_parser.php[^].

—SA
 
Share this answer
 
Hi,
See if following piece of code helps

C#
string testing = "<img src="\"cid:tmpImage.gif\"">,cdefetfdgfdg ,ewrewrewr,<img src="\"cid:tmpImage1.gif\"">,<img src="\"cid:tmpImage2.gif\"">,<img src="\"cid:tmpImage3.gif\"">,<img src="\"cid:tmpImage4.gif\"">";
Regex regex = new Regex(@"(src([^>]+))");
MatchCollection cl = regex.Matches(testing);

foreach (Match match in cl)
{
    Console.WriteLine(match.Value);
}


Its giving me output as
src="cid:tmpImage.gif"
src="cid:tmpImage1.gif"
src="cid:tmpImage2.gif"
src="cid:tmpImage3.gif"
src="cid:tmpImage4.gif"


Hope that serves the purpose. If it helps, mark the answer as solution and/or upvote.

Thanks
Milind
 
Share this answer
 
v2

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