-1

I have the following html:

<div class="album-cover"><a title="Journalist" href="http://abc.is/albums/48592-journalist-103-battle-for-the-hearts-and-minds" target="_self"><img title="Journalist" src="https://i.abc.ee/LF2f/original_journalist-103-battle-for-the-hearts-and-minds.jpeg" alt="Journalist" /></a></div>

I'd like to return only the image string:

   https://i.abc.ee/LF2f/original_journalist-103-battle-for-the-hearts-and-minds.jpeg

The url and content can change everytime.

  • 3
    [Don't use regex](http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags). Use http://php.net/dom instead, to preserve your sanity. ZA̡͊͠͝LGΌ ISͮ̂҉̯͈͕̹̘̱ TO͇̹̺ͅƝ̴ȳ̳ TH̘Ë͖́̉ ͠P̯͍̭O̚​N̐Y̡ H̸̡̪̯ͨ͊̽̅̾̎Ȩ̬̩̾͛ͪ̈́̀́͘ ̶̧̨̱̹̭̯ͧ̾ͬC̷̙̲̝͖ͭ̏ͥͮ͟Oͮ͏̮̪̝͍M̲̖͊̒ͪͩͬ̚̚͜Ȇ̴̟̟͙̞ͩ͌͝S̨̥̫͎̭ͯ̿̔̀ͅ – ceejayoz Oct 28 '16 at 14:58
  • @ceejayoz you know the font you used ruined your links – Phiter Oct 28 '16 at 15:12
  • @PhiterFernandes Argh, it was wrapping fine earlier. http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags – ceejayoz Oct 28 '16 at 15:18

2 Answers2

0

src="([^"]+) works, unless you're testing the regex in the whole document instead of the piece of code you provided

Paul0PT
  • 106
  • 1
  • 18
0

You shouldn't use a regex to parse your html, you could use a xpath expression like this:

//img[@title="Journalist"]/@src

Anyway, if you still want to use a regex you could use:

title="Journalist" src="(.*?)"
Federico Piazza
  • 30,085
  • 15
  • 87
  • 123