jamesmiller Posted September 7, 2011 Share Posted September 7, 2011 Hey guy, I need to find web links on a page that have <a href="/load/blahbla?pk=blah"> and am needing a regex to pick them out, the current code i have is :- preg_match_all('/<a href="\/load\/(.*?)?pk=/i', $page, $pages); coudl anyone help me fix my regex please? thank you in advance Quote Link to comment https://forums.phpfreaks.com/topic/246641-regex-for/ Share on other sites More sharing options...
premiso Posted September 7, 2011 Share Posted September 7, 2011 Since you are dealing with slashes, choose a different delimiter. preg_match_all('#<a href="/load/(.*)?pk=#i', $page, $pages); Should get you what you want. Quote Link to comment https://forums.phpfreaks.com/topic/246641-regex-for/#findComment-1266488 Share on other sites More sharing options...
jamesmiller Posted September 7, 2011 Author Share Posted September 7, 2011 Hm doesnt seem to bring up the relevant information, got it partly working with preg_match_all('!<a href="/load/(.*)?pk=(.*)>!i', $page, $pages); any suggestions on improving that Quote Link to comment https://forums.phpfreaks.com/topic/246641-regex-for/#findComment-1266493 Share on other sites More sharing options...
jamesmiller Posted September 7, 2011 Author Share Posted September 7, 2011 after the PK it needs to be any number aswell ive tried a bnumber of combinations but i havent had any success Quote Link to comment https://forums.phpfreaks.com/topic/246641-regex-for/#findComment-1266497 Share on other sites More sharing options...
xyph Posted September 7, 2011 Share Posted September 7, 2011 $expression = '%<a href="/load/([^?"]++)\?pk=([^"]++)">%'; Quote Link to comment https://forums.phpfreaks.com/topic/246641-regex-for/#findComment-1266513 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.