need to grab a number with a comma

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
jasondavis
Forum Commoner
Posts: 60
Joined: Sat Feb 04, 2006 5:35 pm

need to grab a number with a comma

Post by jasondavis »

I have a script which used to work as the numbers were a solid set of numbers, no commas. Now the numbers I am grabbing sometimes have a comma in them so it only grabs the numbers before the comma

Code: Select all

preg_match("/(\d+) friend/", $html, $msfc);
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: need to grab a number with a comma

Post by Chris Corbyn »

Code: Select all

preg_match("/([\d,]+) friend/", $html, $msfc);
jasondavis
Forum Commoner
Posts: 60
Joined: Sat Feb 04, 2006 5:35 pm

Post by jasondavis »

that worked well thanks, 1 more thing now

I need to search for a friend(s) the ( and ) seem to mess it up how do you escape them or whatever need to be done

Code: Select all

friend(s)
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

jasondavis wrote:that worked well thanks, 1 more thing now

I need to search for a friend(s) the ( and ) seem to mess it up how do you escape them or whatever need to be done

Code: Select all

friend(s)
Escape the parentheses with backslashes just like you do in other languages \( \).
Post Reply