Zum Inhalt springen
uencoder

Extrahieren @mentions from text

Mentions starten mit @ followed durch ein username. Lernen in extrahieren mentions, validieren usernames, und link them in Benutzer profiles.

  1. 1

    A mention is @ followed by a username (letters, digits, underscores, hyphens). The regex @[\w]+ finds mentions. Some platforms allow dots (email-like). The @ must be at the start or preceded by whitespace (otherwise it is part of an email address). Validate extracted usernames against your user database.

  2. 2
    Regex-Tester →

    Find all mentions with @\w[\w.]*\w or @\w+ (simpler). Test against text: "Thanks @alice and @bob_smith for the help! CC: @team.frontend". The tool shows all matches. Distinguish mentions from email addresses by checking for a preceding space or start of string.

  3. 3
    Regex-Ersetzung →

    Link mentions to profiles: replace @username with <a href="/users/username">@username</a>. Use a callback replacement to look up the user ID: replace @([\w]+) with a link to the user's profile if they exist, or leave as text if not found.

Häufige Fragen

How do I distinguish mentions from email addresses?
Prüfen the context: if @ is preceded by a word character (no space), it is likely an email ([email protected]). If preceded by whitespace or start of string, it is a mention (@user). Use a lookbehind: (?<=\s|^)@\w+ or (?:^|\s)@(\w+) to match mentions only.
What characters are allowed in usernames?
Common: letters, digits, underscores ([a-zA-Z0-9_]). Some platforms allow hyphens and dots (but not consecutive dots or trailing dots). Check your platform's username rules. Validate extracted mentions against the user database — not all @word patterns are real users.

Workflows, die diese Aufgabe lösen

Verwandte Tools