Twitter / X Mention Regex
Matches @username mentions in tweets or social posts.
パターン
/@([A-Za-z0-9_]{1,15})/g
→ ビジュアライザーで開くテスト例
Hello @john_doe, thanks @jane123! CC @support team.
コード例
javascript
const regex = /@([A-Za-z0-9_]{1,15})/g;
const result = [...str.matchAll(regex)].map(m => m[1]);python
import re
pattern = re.compile(r'@([A-Za-z0-9_]{1,15})')
result = pattern.findall(text)go
import "regexp"
re := regexp.MustCompile(`@([A-Za-z0-9_]{1,15})`)
result := re.FindAllString(text, -1)socialtwittermention