python - Find strings that begins with a '#' and create link -
i want check whether string (a tweet) begins '#' (i.e. hashtag) or not, , if create link.
below i've tried far doesn't work (error on last line). how can fix , code work purpose?
tag_regex = re.compile(r""" [\b#\w\w+] # hashtag found!""", re.verbose) message = raw_message tag in tag_regex.findall(raw_message): message = message.replace(url, '<a href="http://statigr.am/tag/' + message[1:] + '/">' + message + '</a>')
>>> msg = '#my_tag rest of tweet' >>> re.sub('^#(\w+) (.*)', r'<a href="http://statigr.am/tag/\1">\2</a>', msg) '<a href="http://statigr.am/tag/my_tag">the rest of tweet</a>' >>>
Comments
Post a Comment