-4

i have this :

<img src="http://MyUrl.JPG.jpg" width="180" ...

and i need this :

http://MyUrl.JPG.jpg

thank

Pben
  • 1,081
  • 7
  • 12
  • A very simillar thread here: http://stackoverflow.com/questions/965893/regular-expression-to-extract-the-url-out-of-the-anchor-tag – Jan Kratochvil Mar 01 '12 at 13:54

2 Answers2

5

If that's really all you have you might get away with a regular expression, like

src="([^"]+)

However, you can't and shouldn't try to parse HTML in general with regular expressions. Using regular expressions to parse HTML: why not?

Instead use an HTML parser like Html Agility Pack. I don't know if it's available for WP7, though.

Community
  • 1
  • 1
Andre Loker
  • 8,368
  • 1
  • 23
  • 36
  • The HAP does work with WP7. Get it from source http://htmlagilitypack.codeplex.com/SourceControl/list/changesets – Matt Lacey Mar 01 '12 at 14:47
3

Complete solution with regex :

string source ="<img src=\"http://MyUrl.JPG.jpg\"";
var reg = new Regex("src=(?:\"|\')?(?<imgSrc>[^>]*[^/].(?:jpg|bmp|gif|png))(?:\"|\')?");
var match=reg.Match(source);
if(match.Success)
{
  var encod = match.Groups["imgSrc"].Value;
}
Julien
  • 3,509
  • 20
  • 35