Jump to content

Regex Question


Ninjakreborn

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/207616-regex-question/
Share on other sites

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,]+

Link to comment
https://forums.phpfreaks.com/topic/207616-regex-question/#findComment-1085416
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/207616-regex-question/#findComment-1085472
Share on other sites

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.