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

JavaScript / ECMAScript code

jsJavaScript
const re = new RegExp("https?:\\/\\/(?:www\\.)?(?:twitter|x)\\.com\\/([A-Za-z0-9_]{1,15})(?:\\/status\\/(\\d+))?", "g");
const input = "https://twitter.com/jack/status/20";
const matches = [...input.matchAll(re)];
console.log(matches.map(m => m[0]));

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

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/20

Matches

  • https://twitter.com/jack/status/20

Input

Profile: https://x.com/elonmusk

Matches

  • https://x.com/elonmusk

Input

no twitter links

No 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

Related patterns