How to remove citations and parenthesized text from text in Python

import re
cRegEx  = re.compile('\[[0-9]*\]')
text = 'in a deliberate challenge to the social order[14]'                     
def remove_citations(text):
    return re.sub(cRegEx, '' , text)

print(remove_citations(text))


pText = 'example of if condition if(flag)'
pRegEx  = re.compile('\(.*\)')
def remove_parentheses(pText):
    return re.sub(pRegEx, '', pText)
print(remove_parentheses(pText))

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

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