Ninjakreborn Posted July 13, 2010 Share Posted July 13, 2010 I had some questions a few days ago that Wildteen helped me with. It was working great but I ran into a few issues, and I am trying to figure out how to make this work. Basically the code is: <?php preg_match_all("~\bInlinks\b \(([[:digit:]]+)\)~", $url, $num_backlinks); ?> So in this situation it's suppose to get numbers. The + apparently allows it to get multiple digit numbers. The only situation I have found this does not work in is in the thousands or some such. It adds a "comma" to the number and I am not sure how to screen that out. I was thinking of wildcard but it could be at the 10's or thousands..like 1,200 or 12,000 or even 120,000 or perhaps more. So the comma could be in different places. Is there something that I can replace [[:digit]]+ with that will take into account commas? Quote Link to comment Share on other sites More sharing options...
Ninjakreborn Posted July 13, 2010 Author Share Posted July 13, 2010 One solution is to get the contents of the page like I am doing and then replace all ',' with '' instead. But that is a little resource intensive if there is a simpler way to take that into account for regex. Quote Link to comment Share on other sites More sharing options...
Mchl Posted July 13, 2010 Share Posted July 13, 2010 ([[:digit:]]|,)+ ? Quote Link to comment Share on other sites More sharing options...
cags Posted July 13, 2010 Share Posted July 13, 2010 That code seems way overkill. It matches the POSIX style of digit, within a character class, I have no idea why it also uses a capture group and alteration to match the comma as it could have been placed within the character class. [[:digit:],]+ further more... [0-9,]+ or even... [\d,]+ Quote Link to comment Share on other sites More sharing options...
Ninjakreborn Posted July 13, 2010 Author Share Posted July 13, 2010 Actually whatever the code was before didn't work for some reason. So I went ahead and defaulted to stripping the comma's from the string. I will try out your patterns as well. I am trying to learn more about this Regex, but some of these patterns are really advanced. I have been trying to work with them a lot lately to get better with them. Thanks also for the explanation, it helped me understand what you were doing with it. Thanks again. 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.