Reputation: 6920
I have strings like :
a = "opening Balance 25,07,708.33 |Fixed Assets (Furniture)"
b = "|Add: income during the Yr, 5,95,719.92 |0/Balance 55,221.00"
c = "|Les:- Dep@10% 5,522.00 49,699.00"
I want to get only the floating point numeric values from the strings in a list like :
a_l = ["25,07,708.33"]
b_l = ["5,95,719.92" , "55,221.00"]
c_l = ["5,522.00" , "49,699.00"]
I'm trying this code using regular expression in python :
import re
a_l = a[re.search(r'((\d+\,+)+\d+\.\d{2})', a).span()[0]:re.search(r'((\d+\,+)+\d+\.\d{2})', a).span()[1]]
# same for b_l, c_l
I'm getting output like :
a_l = '25,07,708.33'
b_l = '5,95,719.92'
c_l = '5,522.00'
It's only detecting the first occurance of this kind and then omitting others. What is the right pattern for searching through the floating point numeric values without replacing commas in them?
Upvotes: 2
Views: 41
Reputation: 67968
You can simply do
b = "|Add: income during the Yr, 5,95,719.92 |0/Balance 55,221.00"
import re
a_l = re.findall(r'((?:\d+,+)+\d+\.\d{2})', b)
print a_l
Output:
['5,95,719.92', '55,221.00']
Upvotes: 1