Webflags: g
Twitter / X URL
Match Twitter/X profile and status URLs, capturing the handle and (optional) tweet ID.
Try it in RegexPro →Available in
Pattern
regexengine-agnostic
https?:\/\/(?:www\.)?(?:twitter|x)\.com\/([A-Za-z0-9_]{1,15})(?:\/status\/(\d+))? (flags: g)Raw source: https?:\/\/(?:www\.)?(?:twitter|x)\.com\/([A-Za-z0-9_]{1,15})(?:\/status\/(\d+))?
How it works
https?:\/\/(?:www\.)?(?:twitter|x)\.com matches the domain — both legacy twitter.com and current x.com, with optional www. ([A-Za-z0-9_]{1,15}) captures the handle. (?:\/status\/(\d+))? optionally captures a tweet ID for status URLs.
Examples
Input
https://twitter.com/jack/status/20Matches
https://twitter.com/jack/status/20
Input
Profile: https://x.com/elonmuskMatches
https://x.com/elonmusk
Input
no twitter linksNo match
—Common use cases
- •Embedding tweets in CMS content
- •Social media analytics — extracting tweet IDs from text
- •Migrating links from twitter.com to x.com
- •Citation collection in news / research workflows