[SOLVED]How do I extract price via regex?

I've got a regex that extracts the price with the $, but I ne

Page 1 of 1

2 Replies - 4799 Views - Last Post: 31 December 2008 - 05:38 PM Rate Topic: -----

#1 brawnyman713   User is offline

  • D.I.C Head
  • member icon

Reputation: 0
  • View blog
  • Posts: 139
  • Joined: 21-October 07

[SOLVED]How do I extract price via regex?

Posted 31 December 2008 - 02:27 PM

I know regexes are a universal thing, but I'm writing this in PHP, so this seems like the appropriate place. I'm writing a program that extracts the price and quantity available from a webpage via regexes. For this particular vendor, the price is marked by the only '$' on the page. Therefore, this is my regex:
/\$[0-9.]{1,}/

The problem is that this returns the $ as well as the numbers. I'm currently using str_replace on it to remove the $, but is there a way to write my regular expression so that it requires that the numbers be preceded by a $, but not actually return the $ in the match?

This post has been edited by brawnyman713: 31 December 2008 - 05:45 PM


Is This A Good Question/Topic? 0
  • +

Replies To: [SOLVED]How do I extract price via regex?

#2 girasquid   User is offline

  • Barbarbar
  • member icon

Reputation: 108
  • View blog
  • Posts: 1,825
  • Joined: 03-October 06

Re: [SOLVED]How do I extract price via regex?

Posted 31 December 2008 - 03:36 PM

Couldn't you use capture groups? Something like this:
/\$([0-9.]{1,})/


And then just retrieve that capture group?
Was This Post Helpful? 1
  • +
  • -

#3 brawnyman713   User is offline

  • D.I.C Head
  • member icon

Reputation: 0
  • View blog
  • Posts: 139
  • Joined: 21-October 07

Re: [SOLVED]How do I extract price via regex?

Posted 31 December 2008 - 05:38 PM

I've been making some major changes to the code, and I'm still debugging other parts of the code, so the program no longer gets to that point correctly, for now. However, this is exactly what I need, and thank you

Update: Ok, the code got a major overhaul, and I have all of the kinks worked out. As you said, the capture groups worked perfectly. Thanks

This post has been edited by brawnyman713: 03 January 2009 - 12:43 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1