scheda Posted July 25, 2010 Share Posted July 25, 2010 Hi, So I'm having some trouble with regex... of course... Here's what's happening. I'm building a Google scraper. It goes out, does a search for forums register pages, and grabs the links to them all. I have everything working, I just need the regex to grab the proper links. In my head I see the script grabbing all links that have register.php inside the href area. This is what my regex looks like right now. <a href="(*)register.php" class=l> However, I get this error when it runs. Warning: preg_match_all() [function.preg-match-all]: Compilation failed: nothing to repeat at offset 9 in C:\wamp\www\forumfinder.php on line 33 I'm guessing it has to do with the quotes I have in there. Any thoughts on how to fix this? Thank you in advance! Quote Link to comment https://forums.phpfreaks.com/topic/208856-searching-for-links-in-a-page/ Share on other sites More sharing options...
Hybride Posted July 25, 2010 Share Posted July 25, 2010 What is your entire preg_match statement? The error goes down to that the regex had nothing to match against. Quote Link to comment https://forums.phpfreaks.com/topic/208856-searching-for-links-in-a-page/#findComment-1091042 Share on other sites More sharing options...
scheda Posted July 26, 2010 Author Share Posted July 26, 2010 Here it is. preg_match_all('<a href="(*)register.php" class=l>',$html,$links); Quote Link to comment https://forums.phpfreaks.com/topic/208856-searching-for-links-in-a-page/#findComment-1091069 Share on other sites More sharing options...
cags Posted July 26, 2010 Share Posted July 26, 2010 A * represents 0 or more characters matching the character preceding the *, in your case however the preceding character is an non-escaped bracket which is part of a capture group, therefore the * has 'nothing to repeat'. I will assume you are trying to capture URL of all anchor tags that have a href ending with register.php. On a side note your pattern is assumably missing delimiters, the only reason it hasn't thrown an error is the fact that the character at the start and end of your pattern, just happen to be valid delimiters. preg_match_all('<a href="(.*?)register.php" class=l>',$html,$links); Quote Link to comment https://forums.phpfreaks.com/topic/208856-searching-for-links-in-a-page/#findComment-1091168 Share on other sites More sharing options...
sasa Posted July 29, 2010 Share Posted July 29, 2010 or preg_match_all('<a href="[^"]*register.php" class=l>',$html,$links); Quote Link to comment https://forums.phpfreaks.com/topic/208856-searching-for-links-in-a-page/#findComment-1092685 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.