Replacing substring using regex in python

I have a following string:

A cumulative 173,326 MMSCF of gas at
a daily average of 633 MMSCF and 10,974 barrels of condensate (40 barrels per day) were produced
from Mari Field during the period as against 164,108 MMSCF of gas at daily average of 597 MMSCF
and 15,507 barrels of condensate (56 barrels per day) for the corresponding period as per the
requirement / withdrawal of the customers.

Here I want to replace substrings like “(40 barrels per day)” with “at a daily average of 40”.
So in the above string, I want these replacements:

(40 barrels per day) -> at a daily average of 40
(56 barrels per day) -> at a daily average of 40

How can I achieve this?

Leave a Reply

Your email address will not be published. Required fields are marked *