diff --git a/files/helpers/regex.py b/files/helpers/regex.py
index dc4e931386..2cadfa2edf 100644
--- a/files/helpers/regex.py
+++ b/files/helpers/regex.py
@@ -8,7 +8,7 @@ from .config.const import *
valid_username_chars = 'a-zA-Z0-9_\-'
valid_username_regex = re.compile("^[a-zA-Z0-9_\-]{3,25}$", flags=re.A)
-mention_regex = re.compile('(^|\s|>)@([a-zA-Z0-9_\-]{1,30})(?!([^<]*<\/(code|pre|a)>|[^`]*`))', flags=re.A)
+mention_regex = re.compile('@([a-zA-Z0-9_\-]{1,30})(?!([^<]*<\/(code|pre|a)>|[^`]*`))', flags=re.A)
group_mention_regex = re.compile('!([a-z0-9_\-]{3,25})(?!([^<]*<\/(code|pre|a)>|[^`]*`))', flags=re.A|re.I)
everyone_regex = re.compile('(^|\s|>)!(everyone)(?!([^<]*<\/(code|pre|a)>|[^`]*`))', flags=re.A)
diff --git a/files/helpers/sanitize.py b/files/helpers/sanitize.py
index 6948242a28..46b48cf417 100644
--- a/files/helpers/sanitize.py
+++ b/files/helpers/sanitize.py
@@ -375,7 +375,7 @@ def sanitize(sanitized, golden=True, limit_pings=0, showmore=True, count_marseys
v = getattr(g, 'v', None)
- names = set(m.group(2) for m in mention_regex.finditer(sanitized))
+ names = set(m.group(1) for m in mention_regex.finditer(sanitized))
if limit_pings and len(names) > limit_pings and not v.admin_level >= PERMS['POST_COMMENT_INFINITE_PINGS']: abort(406)
users_list = get_users(names, graceful=True)
users_dict = {}
@@ -385,22 +385,22 @@ def sanitize(sanitized, golden=True, limit_pings=0, showmore=True, count_marseys
users_dict[u.original_username.lower()] = u
def replacer(m):
- u = users_dict.get(m.group(2).lower())
+ u = users_dict.get(m.group(1).lower())
if not u:
return m.group(0)
- return f'{m.group(1)}
@{u.username}'
+ return f'
@{u.username}'
sanitized = mention_regex.sub(replacer, sanitized)
if FEATURES['PING_GROUPS']:
for i in group_mention_regex.finditer(sanitized):
- name = i.group(2).lower()
+ name = i.group(1).lower()
if name == 'everyone':
- sanitized = group_mention_regex.sub(r'\1!\2', sanitized)
+ sanitized = group_mention_regex.sub(r'!\1', sanitized)
else:
existing = g.db.get(Group, name)
if existing:
- sanitized = sanitized.replace(i.group(0), f'{i.group(1)}!{name}', 1)
+ sanitized = sanitized.replace(i.group(0), f'!{name}', 1)
soup = BeautifulSoup(sanitized, 'lxml')