JavaScript / ECMAScript

Slack User Mention in JS

Match Slack user mentions in their raw form <@U01234ABC> as delivered by the Events API.

Try it in the JS tester →

Pattern

regexJS
<@U[A-Z0-9]{8,}>   (flags: g)

JavaScript / ECMAScript code

jsJavaScript
const re = new RegExp("<@U[A-Z0-9]{8,}>", "g");
const input = "cc <@U01234ABC> please review";
const matches = [...input.matchAll(re)];
console.log(matches.map(m => m[0]));

Uses `String.prototype.matchAll` for global iteration (Node 12+ / all modern browsers).

How the pattern works

Literal <@U prefix, then 8 or more uppercase alphanumeric characters (Slack's ID alphabet), closed by >. Matches user IDs regardless of legacy or modern length.

Examples

Input

cc <@U01234ABC> please review

Matches

  • <@U01234ABC>

Input

pinged <@UABCDEF123GH> earlier

Matches

  • <@UABCDEF123GH>

Input

no mentions

No match

Same pattern, other engines

← Back to Slack User Mention overview (all engines)