Monday, February 10, 2014

Python: Replace All Occurrences in String

Problem:

str = "never asserted as the ''only'' sufficient condition for ''Q'', other factors could account for ''Q'' (while ''P'' was false).<ref>{{cite web |url = http://www.fallacyfiles.org/afthecon.html |title = Fallacy Files |work = http://www.fallacyfiles.org |publisher  = Fallacy Files |accessdate = 9 May 2013}}</ref>To put it differently"


Replace <ref&gt.*</ref> by ''

Solution:

import re

str = re.sub(r'<ref&gt.*</ref>', "", str)

print str

No comments:

Post a Comment