diff --git a/templatetags/ticket_to_link.py b/templatetags/ticket_to_link.py
index cf5dfa57..c5f84eea 100644
--- a/templatetags/ticket_to_link.py
+++ b/templatetags/ticket_to_link.py
@@ -37,7 +37,7 @@ def num_to_link(text):
return text
matches = []
- for match in re.finditer(" #(\d+)", text):
+ for match in re.finditer(r"(?:[^&]|\b|^)#(\d+)\b", text):
matches.append(match)
for match in ReverseProxy(matches):
@@ -52,7 +52,7 @@ def num_to_link(text):
if ticket:
style = ticket.get_status_display()
- text = "%s#%s%s" % (text[:match.start()], url, style, match.groups()[0], text[match.end():])
+ text = "%s #%s%s" % (text[:match.start()], url, style, match.groups()[0], text[match.end():])
return mark_safe(text)
register = template.Library()