Go (RE2)

Slack User Mention in GO

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

Try it in the GO tester →

Pattern

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

Go (RE2) code

goGo
package main

import (
	"fmt"
	"regexp"
)

func main() {
	re := regexp.MustCompile(`<@U[A-Z0-9]{8,}>`)
	input := `cc <@U01234ABC> please review`
	for _, match := range re.FindAllString(input, -1) {
		fmt.Println(match)
	}
}

Uses `regexp.MustCompile` (panics on bad patterns at startup) and `FindAllString` for all matches.

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)