I want to extract digits after 'ID' occurrence in the following text This is how I am able to get it.
import re
txt="Recharge done on 28-12-2017 04:57PM,MRP:Rs9.00,GST 18% payable by Company/Distributor/Retailer:Rs1.37, ID 147894886."
# 'ID' need to be present as mandatory group
regex = '(id)(.*?)(\d+})'
rg = re.compile(regex ,re.IGNORECASE|re.DOTALL)
m = rg.search(txt)
if m:
print m.group(3)
When I run the following code, it prints
147894886
Here comes the problem
If txt become like this
txt="Recharge done on 28-12-2017 04:57PM,MRP:Rs9.00,GST 18% payable by Company/Distributor/Retailer:Rs1.37, TransID 147894886."
and "Trans" word appears before "ID" then I dont want to extract digits. How to do that in regex (i.e don't extract digits if "TransID" is present before digits but only if "ID" is present then extract digits)