I am trying to write a regular expression to extract the href
and anchor
text of a list of URLs from an HTML source. The anchor
text can be any values.
The HTML part goes as follow:
<div class="links"><a rel="nofollow" target="_blank" href="http://url1.com" class="get-all">URL1</a><a rel="nofollow" target="_blank" href="http://url2.com" class="get-all">This is Url-2</a><a rel="nofollow" target="_blank" href="http://url3.com" class="get-all">This is Url-3</a><a rel="nofollow" target="_blank" href="http://url4.com" class="get-all">Sweet URL 4</a></div>
I tried the following regular expression, but it's not working since it grabs everything before the </a>
tag and fails.
preg_match_('/<a rel="nofollow" target="_blank" href="(.*)" class="see-all">(.*)<\/a>/', $source , $website_array);
What would be a working regular expression to extract my required data?