Skip to content
Advertisement

Python regex to replace a Particular line in paragraphs as per regex only not whole file

JavaScript

Now python code to re.sub to replace UNWANTED TEXT only inside paragraphs keep UNWANTED TEXT Outside paragraphs

JavaScript

But the output replace all instance of UNWANTED TEXT in through out the file

JavaScript

but i expect like this

JavaScript

Please help.

Advertisement

Answer

Your demo input should have been more ‘minimal’. However, I tried to understand your requirement and I tried re.split works:

JavaScript

Output:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement