跳到主要内容
uencoder

提取 @mentions from text

Mentions 启动具有 @ followed 通过 username. Learn 到提取 mentions, 验证 usernames, 和 link 它们到 用户 profiles.

  1. 1

    mention 是 @ followed 通过 username (letters, digits, underscores, hyphens). regex @[\w]+ finds mentions. 一些 platforms 允许 dots (email-like). @ 必须是 在启动或 preceded 通过 whitespace (否则它 是部分的 email address). Validate extracted usernames 针对你的用户数据库.

  2. 2
    正则表达式测试器 →

    Find 所有 mentions 具有 @\w[\w.]*\w 或 @\w+ (simpler). Test 针对文本: "Thanks @alice 和 @bob_smith 为 help! CC: @team.frontend". tool shows 所有 matches. Distinguish mentions 从 email addresses 通过 checking 为 preceding space 或启动的 字符串.

  3. 3
    正则表达式替换器 →

    Link mentions 到 profiles: 替换 @username 具有 < href="/users/username">@username</>. Use 回调 replacement 到 look 上用户 ID: 替换 @([\w]+) 具有 link 到用户's 性能分析如果它们存在, 或 leave as 文本如果不 found.

常见问题

如何 I distinguish mentions 从 email addresses?
检查 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.
什么 characters 是允许在 usernames?
常见: letters, digits, underscores ([a-zA-Z0-9_]). 一些 platforms 允许 hyphens 和 dots (但不 consecutive dots 或 trailing dots). Check 你的平台's username rules. Validate extracted mentions 针对用户数据库 — 不所有 @字 patterns 是实数 users.

解决此任务的工作流

相关工具