Advertisement

Pattern library / URLs & Marketing

Mention Regex (@handles)

Mentions look simple — @ plus a handle — until a paragraph of email addresses lights up as matches. This page gives the plain pattern, the boundary variant that behaves in RE2 engines (no lookbehind!), and the platform notes that decide whether @user-name is one handle or two.

The pattern
@[A-Za-z0-9_]+
Load this pattern into the tester →

How the pattern works

Test it: match & no-match examples

Every row is loaded straight into the tester — click Try to see the match live:

InputResultWhy
Hey @countoftuscany, nice postMatchfinds @countoftuscanyTry →
write ada@example.com for helpMatchmatches @example — email overlap is real (pitfalls)Try →
@user-name rocksMatchstops at the hyphen: @user onlyTry →
price @ $5No matchhandle must start right after @Try →
at sign only @No matchnothing after the @Try →
contact us todayNo matchno @ at allTry →

Where to use it

JavaScript

const all = text.match(/@[A-Za-z0-9_]+/g) || [];
// boundary version — skips emails:
const re = /(^|[^A-Za-z0-9_.])@([A-Za-z0-9_]+)/g;

Python

import re
handles = re.findall(r'@([A-Za-z0-9_]+)', text)
# with boundary:
real = [m.group(2) for m in re.finditer(r'(^|[^\w.])@([A-Za-z0-9_]+)', text)]

BigQuery / GA4 (RE2)

WHERE REGEXP_CONTAINS(msg, r'(^|[^A-Za-z0-9_.])@support_team\b')

Common mistakes

Test this pattern on your own data
Paste it into the free tester with your real strings — nothing leaves your browser.
Open the regex tester →

FAQ

How do I match a mention but not an email?

Anchor the @ to a non-word boundary: (^|[^A-Za-z0-9_.])@([A-Za-z0-9_]+). Group 1 guarantees nothing word-like precedes the @, which emails always violate (local part or dot).

Why is my lookbehind pattern rejected in BigQuery?

RE2 has no lookarounds by design (that is what guarantees linear time). Replace the lookbehind with the group trick from the notes — same result, valid RE2.

How do I extract all mentions from a message?

@([A-Za-z0-9_]+) with a global search: JavaScript match(/@([A-Za-z0-9_]+)/g), Python findall(r'@([A-Za-z0-9_]+)', text).

Hashtag Regex - Match #tags in Posts & Text · Email Validation Regex — Practical Pattern to Test · Slug Regex — Match lowercase-hyphen URL Slugs

For GA4-specific patterns, see the GA4 regex cheat sheet, the page path regex guide, the event filter regex guide, the GA4 regex match types, the custom channel grouping guide and RE2 vs PCRE. Browse the full regex pattern library.