Created
November 30, 2011 16:06
-
-
Save joshz/1409617 to your computer and use it in GitHub Desktop.
clean some content inside tags
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
s = 'abcd<aaa>some thing <#^&*some more!#$@ </aaa> abcdefgasf <aaa>asfaf %^&*$saf asf %$^ </aaa> <another tag> some text </another tag> <aaa>sfafaff#%%%^^</aaa>' | |
inside_tags = re.findall('<aaa>(.+?)</aaa>', s) | |
cleaned_contents = [ re.sub('\W', '_' ,content) for content in inside_tags ] | |
zipped = zip(inside_tags, cleaned_contents) | |
s | |
for old, new in zipped: | |
s = s.replace(old, new) | |
print s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment