I want to get all the percentage from above string with decimal or without decimal points. I also want to get % sign.
string = """Bachelor of Engineering in Electronics from in 2013 with 60%.
Diploma (Electronics & Video Engineering) from in 2009 with 79.39%.
SSC from in 2006 with 61.71%."""
I have tried as below
re.findall(r'\d+%|([0-9]\d?)\.\d+%', string)
getting output as
['', '79', '61']
But I want output as below
['60%', '79.39%', '61.71%']
Anybody can tell where I am going wrong and regex to get expected output.
You can use the RegEx (\d+(\.\d+)?%)
\d+ captures 1 or more digits
(\.\d+)? captures a dot and 1 or more digits 0 or 1 time
% captures % literally
Demo.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With