Python (re)

Slack User Mention in PY

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

Try it in the PY tester →

Pattern

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

Python (re) code

pyPython
import re

pattern = re.compile(r"<@U[A-Z0-9]{8,}>")
input_text = "cc <@U01234ABC> please review"
for m in pattern.finditer(input_text):
    print(m.group(0))

Stdlib `re` module — no third-party dependency. Works on Python 3.6+.

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)