Notifications
You’re not receiving notifications from this thread.
Regexp for prices or how to detect price in a smart way
Any regexp experts here? I have the following situation:
- get an invoice
- scan it for prices and save the highest number
- success 🍾
I do this with a .scan(/…/)
. Pretty fast in Ruby. ✨
Format of pricing, and thus why the regexp gets tricky, can be really all over the place, some examples:
€100,-
€ 59,95
$ 100
$ 10.00
29 €
49,95 €
50 $
And any combination of above, including different type of spaces between currency and number :)
Current regexp looks like this, but that doesn't take into account the currency symbol after the price: /([€$]{1}[ \s]?)(\d{1,6}([,.]\d{1,2})?)/
.
I am starting to think I need to think outside of using just regexp and need some ruby magic here, but hope any of you smart folks can help with that too.
Edit: just typing this post, I got the idea of separating the two. Scan for currency symbol first and then check for highest price. 💡
Hey Jack,
Did you ever come up with a clean solution for this?
I think your final edit (separating the two first) is probably the way I would have tried to tackled it, although my regex skills are horrid... Do you account for currency conversion rates to determine if a value is really higher than the other, or is it purely based on the face value?