Regex Library
Regex Library

15 patterns

Social Media Regex Patterns

Social media validation patterns for Twitter/X, Instagram, GitHub, LinkedIn, and other major platforms. Validate usernames, extract hashtags, and parse profile URLs.

Common Use Cases

Social login formsProfile link validationHashtag extractionMention parsing

All Social Media Patterns

YouTube Video ID

Validates the 11-character YouTube video identifier (anchored).

^[a-zA-Z0-9_-]{11}$

Twitter/X Username

Validates Twitter/X usernames (1-15 chars, letters, numbers, underscore).

^@?[A-Za-z0-9_]{1,15}$

Discord Snowflake ID

Validates Discord IDs (17-19 digit snowflakes).

^\d{17,19}$

LinkedIn Profile URL

Validates LinkedIn profile URLs

^https?://(www\.)?linkedin\.com/in/[a-zA-Z0-9-]+/?$

Instagram Username

Validates Instagram usernames (with or without @)

^@?[a-zA-Z0-9._]{1,30}$

Twitter / X Handle

Validates Twitter/X usernames (1–15 alphanumeric chars or underscores).

^@?[A-Za-z0-9_]{1,15}$

GitHub Username

Validates GitHub usernames (alphanumeric and hyphens, max 39 chars, no leading/trailing or consecutive hyphens).

^(?!-)(?!.*--)[a-zA-Z0-9-]{1,39}(?<!-)$

TikTok Username

Validates TikTok usernames (2-24 chars, letters, numbers, dots, underscores).

^@?[a-zA-Z0-9_.]{2,24}$

YouTube Channel URL

Validates YouTube channel URLs (handle @, /c/, /channel/ formats).

^https?://(www\.)?youtube\.com/(c/|channel/|@)[\w-]+$

Discord Invite Link

Matches a Discord invite URL (discord.gg/xxx or discord.com/invite/xxx).

^(?:https?:\/\/)?(?:www\.)?(?:discord\.gg|discord(?:app)?\.com\/invite)\/[a-zA-Z0-9-]+$

WhatsApp Link

Matches WhatsApp click-to-chat (wa.me), group invite (chat.whatsapp.com), or API links.

^https:\/\/(?:wa\.me|chat\.whatsapp\.com|api\.whatsapp\.com)\/[\w?=&%+/-]+$

Telegram Username

Validates Telegram usernames: 5–32 characters, must start with a letter, alphanumeric and underscore allowed.

^@?[a-zA-Z][a-zA-Z0-9_]{4,31}$

Reddit Username

Matches a Reddit username with optional u/ or /u/ prefix. 3–20 chars.

^(?:\/?u\/)?[A-Za-z0-9_-]{3,20}$

LinkedIn Company URL

Matches a LinkedIn company page URL and captures the company slug.

^https?:\/\/(?:www\.|[a-z]{2,3}\.)?linkedin\.com\/company\/([a-zA-Z0-9._-]{2,100})\/?$

Discord User Mention

Matches Discord user mentions: <@id> or legacy <@!id>.

^<@!?\d{17,19}>$

Frequently Asked Questions

How do I validate a Twitter/X username?

Use ^@?[A-Za-z0-9_]{1,15}$ - 1 to 15 alphanumeric characters or underscores, no spaces.

How do I extract hashtags from text?

Use /#[\w]+/g - matches all hashtags in a string.

How do I extract @mentions from text?

Use /@[A-Za-z0-9_]{1,15}/g - matches all valid Twitter-style mentions.

Looking for patterns in other categories?

Browse all 250 patterns