Jump to content

Regex to extract URL with special characters


abhi_madhani

Recommended Posts

I am trying to extract URL's from html page by using following Regular Expression.

<a href="      (....till....)     "> Name </a>

 

preg_match_all('/<\s*a\s+[^>]*href\s*=\s*[\"\']?([^\"\'>]+)[\"\']>(.*)<\/a>/isU'

 

It works perfectly on most URL's. But it fails to recognise following kind of urls in HTML.

 

http://en.wikipedia.org/wiki/B'ham - Note the single quotation in the B'ham.

 

The URL's in the HTML are not encoded for special characters, hence I have to build my regex to count in URL's which have special characters in them.

Could anyone guide me for solutions towards this bend?

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.