Mercurial > kallithea
diff rhodecode/lib/utils2.py @ 2201:ea5ff843b200 beta
#426 fixed mention extracting regex
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Wed, 18 Apr 2012 02:07:22 +0200 |
parents | 8ecfed1d8f8b |
children | 17ff5693566b |
line wrap: on
line diff
--- a/rhodecode/lib/utils2.py Tue Apr 17 23:50:32 2012 +0200 +++ b/rhodecode/lib/utils2.py Wed Apr 18 02:07:22 2012 +0200 @@ -392,14 +392,18 @@ return cs +MENTIONS_REGEX = r'(?:^@|\s@)([a-zA-Z0-9]{1}[a-zA-Z0-9\-\_\.]+)(?:\s{1})' + + def extract_mentioned_users(s): """ Returns unique usernames from given string s that have @mention :param s: string to get mentions """ - usrs = {} - for username in re.findall(r'(?:^@|\s@)(\w+)', s): - usrs[username] = username + usrs = set() + for username in re.findall(MENTIONS_REGEX, s): + usrs.add(username) - return sorted(usrs.keys()) + return sorted(list(usrs), key=lambda k: k.lower()) +