Last active
April 25, 2016 04:34
-
-
Save songcser/a59f1e8bb46ec12346de1666dc7f504a to your computer and use it in GitHub Desktop.
This file contains 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
python 2.x | |
title = u'#黄致列 我爱你 #映客 直播 #baidu show #fffff' | |
p = re.compile(u'#[\w\u4e00-\u9fa5]+\s?') | |
t = title.encode("utf-8") | |
tags = p.findall(title) | |
for tag in tags: | |
tag = tag.encode("utf-8") | |
print(tag) | |
newtag = tag[0:len(tag)-1]+"# " | |
print(newtag) | |
title = t.replace(tag, newtag) | |
print(t) | |
# python 3.x | |
title = '#黄致列 我爱你 #映客 直播 #baidu show #fffff' | |
p = re.compile('#[\w\u4e00-\u9fa5]+\s?') | |
tags = p.findall(title) | |
for tag in tags: | |
print(tag) | |
newtag = tag[0:len(tag)-1]+"# " | |
print(newtag) | |
title = title.replace(tag, newtag) | |
print(title) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment