Answer the question
In order to leave comments, you need to log in
How to process Cyrillic hashtags?
Good day to all.
There is a piece of code for searching hashtags in the text:
pattern= re.compile(r'\#\w+')
hashtags = re.findall(pattern, text)
Answer the question
In order to leave comments, you need to log in
python3
In [2]: print(re.findall(re.compile(r'\#\w+', re.IGNORECASE),
"#1aaa sdfs #ввв2 dfsdf sdf s"))
['#1aaa', '#ввв2']
In [2]: print(re.findall(re.compile(ur'\#[0-9a-zа-я_-]+', re.IGNORECASE),
u"#1aaa sdfs #ввв2 dfsdf sdf s"))
[u'#1aaa', u'#\u0432\u0432\u04322']
In [2]: print(re.findall(re.compile(r'\#\w+', re.IGNORECASE|re.U),
u"#1aaa sdfs #ввв2 dfsdf sdf s"))
[u'#1aaa', u'#\u0432\u0432\u04322']
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question