Skip to content

Instantly share code, notes, and snippets.

@songcser
Last active April 25, 2016 04:34
Show Gist options
  • Save songcser/a59f1e8bb46ec12346de1666dc7f504a to your computer and use it in GitHub Desktop.
Save songcser/a59f1e8bb46ec12346de1666dc7f504a to your computer and use it in GitHub Desktop.
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