LinkedIn URL Regex
Matches a LinkedIn personal profile, company page, or legacy public profile URL.
Regex Pattern
^https?:\/\/(?:www\.)?linkedin\.com\/(?:in|company|pub)\/[\w-]+\/?$Pattern Breakdown
Hover over a token to see what it does.
| Token | Meaning |
|---|---|
| ^ | Anchors the match to the start of the string |
| https? | Matches http or https |
| :\/\/ | Literal :// scheme separator |
| (?:www\.)? | Optional www. subdomain prefix |
| linkedin\.com\/ | Literal linkedin.com host followed by a slash |
| (?:in|company|pub) | Non-capturing group matching the profile type segment: in (personal), company, or pub (legacy) |
| [\w-]+ | The profile or company slug, made of word characters and hyphens |
| \/?$ | Optional trailing slash, then end of string |
Detailed Explanation
What it does
This pattern validates that a string is a LinkedIn URL pointing to a personal profile (/in/), a company page (/company/), or a legacy public profile (/pub/), followed by a valid slug and an optional trailing slash.
Why it works
The path-type alternation (?:in|company|pub) restricts matches to LinkedIn's known profile URL shapes rather than accepting any arbitrary path on the domain. The slug itself is matched with [\w-]+, reflecting how LinkedIn generates vanity URLs from names and company handles using letters, digits, underscores, and hyphens.
Common use cases
- Validating a LinkedIn profile link field on a resume or job application form
- Filtering a list of social links to find LinkedIn company pages specifically
- Normalizing LinkedIn URLs by stripping trailing slashes or query parameters before storage
- Detecting whether a submitted URL is a personal profile versus a company page
Edge cases
- Both http and https schemes are accepted, along with an optional www. prefix
- A trailing slash after the slug, like /in/johndoe/, is accepted because of the optional \/? before the end anchor
- Legacy /pub/ profile URLs, which LinkedIn used before switching entirely to /in/, are still matched
- A bare linkedin.com/in/ path with no slug is rejected because [\w-]+ requires at least one character
- Locale-prefixed LinkedIn domains such as de.linkedin.com are not matched since only the www. prefix is optional, not arbitrary subdomains
Limitations
- Does not verify that the referenced profile or company page actually exists
- Does not match LinkedIn post, job listing, or article URLs, only profile and company page URLs
- Country-specific LinkedIn subdomains other than www are not recognized without extending the pattern
Interactive Tester
Edit the pattern or text below — matching runs live in your browser.
Test Cases
Editable — add your own inputs to see if they pass.
| Input | Expected | Result | |
|---|---|---|---|
| Pass | |||
| Pass | |||
| Pass | |||
| Pass | |||
| Pass | |||
| Pass | |||
| Pass |
Language Variants
Production-ready examples in 12 languages.
const linkedinUrlRegex = /^https?:\/\/(?:www\.)?linkedin\.com\/(?:in|company|pub)\/[\w-]+\/?$/;
console.log(linkedinUrlRegex.test('https://www.linkedin.com/in/johndoe')); // trueCommon Mistakes
Matching any linkedin.com path, including feed, jobs, or article URLs, as if they were profile links
Fix: Restrict the path segment to the known profile/company prefixes with (?:in|company|pub) rather than a wildcard
Rejecting valid URLs with a trailing slash because the end anchor doesn't account for it
Fix: Add an optional \/? immediately before the $ end anchor
Assuming the /pub/ prefix is invalid because LinkedIn deprecated it
Fix: Keep /pub/ in the alternation since old shared links using that format may still be encountered
Performance Notes
- The small fixed alternation (?:in|company|pub) is checked quickly since each option is a short literal
- The slug character class [\w-]+ has no ambiguity with neighboring tokens, so no catastrophic backtracking occurs
- Anchoring with ^ and $ prevents unnecessary scanning across the whole input for a match
Browser Compatibility
| Engine | Supported | Notes |
|---|---|---|
| Chrome | Yes | — |
| Firefox | Yes | — |
| Safari | Yes | — |
| Edge | Yes | — |
| Node.js | Yes | — |