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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.