I am using python regex to find all prices in a string. Thus far I am only having trouble managing the symbols correctly.
This code, with the input: 'happy$37.54000happy$34$3454$3333€27.80€3.00.33.2£27.000'
import sys
import re
price = sys.argv[1]
new = re.findall(r'[\$\20AC\00A3]{1}\d+\.?\d{0,2}',price,re.UNICODE)
for prices in new:
print prices
ouputs:
$37.54
$34
$3454
$3333
What I would like is:
$37.54
$34
$3454
$3333
€27.80
€3.00
£27.00
If I add the euro sign into the code the file cannot compile given that it is not a unicode character. I was thinking that since 20AC
is the unicode for the euro symbol and \00A3
is the unicode for the pound symbol that that would work, but it does not.
I believe that the issues lies in this part of the code:...
[\$\20AC\00A3]...
Any help would be greatly appreciated
EDIT FOR FUTURE PEOPLE - THIS IS THE BEST CODE ANSWER:
# -*- coding: utf-8 -*-
import sys
import re
price = sys.argv[1]
new = re.findall(r'[$€£]{1}\d+\.?\d{0,2}',price,re.UNICODE)
for prices in new:
print prices