burhankhan Posted January 29, 2007 Share Posted January 29, 2007 Hi:I have this regular expression to find links in a page.[code]$urlpattern = "/<a[^>]+href=\"([^\"]+)/i";[/code]This will find links like that: href="www.domain.com"What will be regular expression to find link of href='www.domain.com' also???see difference of single quote (') and double quote (")I need regular express that can find both kind of links (single quote, double quote)Any help will be highly appreciate.ThanksBurhan Khan Quote Link to comment Share on other sites More sharing options...
HuggieBear Posted January 29, 2007 Share Posted January 29, 2007 Try this:[code]$urlpattern = "/<a[^>]+href=(?:\"|')([^'\"]+)/i";[/code]RegardsHuggie Quote Link to comment Share on other sites More sharing options...
burhankhan Posted January 29, 2007 Author Share Posted January 29, 2007 Thank you so much. Its working :) Quote Link to comment Share on other sites More sharing options...
HuggieBear Posted January 29, 2007 Share Posted January 29, 2007 Excellent, make sure that you mark the topic as 'SOLVED'.RegardsHuggie Quote Link to comment Share on other sites More sharing options...
linuxdream Posted January 29, 2007 Share Posted January 29, 2007 Unfortunately, HTML does not require either ' or ". So you have to compensate for that too. Quote Link to comment Share on other sites More sharing options...
HuggieBear Posted January 29, 2007 Share Posted January 29, 2007 OK, give this a try and run with it...[code]$urlpattern = "/<a[^>]+href=(?:\"|')?([^'\">]+)/i";[/code][b]Edit:[/b] I've tested this and it seems to work fine.RegardsHuggie Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.