Extract currency amount from string in Python -
i'm making program takes currency string , converts in other currencies. example, if string 'the car cost me $13,250'
need $
, 13250
. have regex (?:\£|\$|\€)(?:.{1,})
sort of it, there reasonably large possibility string might have more 1 price, using different currencies. no know how effectively.
what need know how extract of prices string. think if regex returns ['$12,250,000','£14,500,123','£120.25']
fine because can use number:
prices = ['$12,250','£14,500','£120'] value in prices: value.replace(',','')
and currency:
for c in prices: currency = c[0]
then there problem price might not whole number, , might $12.54
. on how initial list of prices great.
this regular expression work better purposes:
(?:[\£\$\€]{1}[,\d]+.?\d*)
try out here.
then sainoba notes, can use re.findall
or re.finditer
matches.
then can extract currency first character, remove commas, , split on decimal point if needed.
Comments
Post a Comment