Social
LinkedIn profile URL Regex
LinkedIn personal profiles live under the /in/ path, followed by a public profile slug of letters, digits and hyphens. This pattern accepts that form with or without https, with www or a country subdomain such as uk, and with an optional trailing slash. It is useful on job applications, CRM imports and speaker forms where you want a personal profile and not a company page, which uses /company/ instead. It does not accept query strings or tracking parameters, so strip those first. A matching link is only well-formed; the profile behind it may be private, renamed or deleted.
Pattern (JavaScript)
/^(?:https?://)?(?:[a-z]{2,3}\.)?linkedin\.com/in/[A-Za-z0-9-]{3,100}/?$/Starts at the start of the line/string, then (the text "http", then the character "s", optionally (zero or one time), then the text "://"), optionally (zero or one time), then (a lowercase letter, between 2 and 3 times, then the character "."), optionally (zero or one time), then the text "linkedin.com/in/", then one of the characters A-Za-z0-9-, between 3 and 100 times, then the character "/", optionally (zero or one time), then the end of the line/string.
Examples
Matches
- ✓ https://www.linkedin.com/in/test-user-123
- ✓ linkedin.com/in/ali-test/
- ✓ https://uk.linkedin.com/in/sample-profile
Does not match
- ✗ https://www.linkedin.com/company/example-co
- ✗ https://linkedin.com/in/
- ✗ https://example.com/in/test-user
- ✗ https://www.linkedin.com/in/test_user
Try it
0 matches (JavaScript engine)
https://www.linkedin.com/in/test-user-123
linkedin.com/in/ali-test/
https://uk.linkedin.com/in/sample-profile
https://www.linkedin.com/company/example-co
https://linkedin.com/in/
https://example.com/in/test-user
https://www.linkedin.com/in/test_userCode in 8 languages
Converted automatically from the JavaScript pattern; language-specific notes are shown where the syntax or support differs.
JavaScript
const re = /^(?:https?:\/\/)?(?:[a-z]{2,3}\.)?linkedin\.com\/in\/[A-Za-z0-9-]{3,100}\/?$/g;
const text = "https://www.linkedin.com/in/test-user-123";
const matches = [...text.matchAll(re)].map((m) => m[0]);
console.log(matches);Python
import re
pattern = re.compile(r'^(?:https?://)?(?:[a-z]{2,3}\.)?linkedin\.com/in/[A-Za-z0-9-]{3,100}/?$')
text = 'https://www.linkedin.com/in/test-user-123'
matches = [m.group(0) for m in pattern.finditer(text)]
print(matches)PHP
<?php
$pattern = '#^(?:https?://)?(?:[a-z]{2,3}\.)?linkedin\.com/in/[A-Za-z0-9-]{3,100}/?$#';
$text = 'https://www.linkedin.com/in/test-user-123';
preg_match_all($pattern, $text, $matches);
print_r($matches[0]);Java
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Main {
public static void main(String[] args) {
Pattern pattern = Pattern.compile("^(?:https?://)?(?:[a-z]{2,3}\\.)?linkedin\\.com/in/[A-Za-z0-9-]{3,100}/?$");
String text = "https://www.linkedin.com/in/test-user-123";
Matcher matcher = pattern.matcher(text);
while (matcher.find()) {
System.out.println(matcher.group());
}
}
}Go
package main
import (
"fmt"
"regexp"
)
func main() {
re := regexp.MustCompile(`^(?:https?://)?(?:[a-z]{2,3}\.)?linkedin\.com/in/[A-Za-z0-9-]{3,100}/?$`)
text := "https://www.linkedin.com/in/test-user-123"
fmt.Println(re.FindAllString(text, -1))
}C#
using System;
using System.Text.RegularExpressions;
var pattern = new Regex(@"^(?:https?://)?(?:[a-z]{2,3}\.)?linkedin\.com/in/[A-Za-z0-9-]{3,100}/?$");
var text = "https://www.linkedin.com/in/test-user-123";
foreach (Match m in pattern.Matches(text))
{
Console.WriteLine(m.Value);
}Rust
// Cargo.toml: regex = "1"
use regex::Regex;
fn main() {
let re = Regex::new(r"^(?:https?://)?(?:[a-z]{2,3}\.)?linkedin\.com/in/[A-Za-z0-9-]{3,100}/?$").unwrap();
let text = "https://www.linkedin.com/in/test-user-123";
for m in re.find_iter(text) {
println!("{}", m.as_str());
}
}- Add regex = "1" under [dependencies] in Cargo.toml.
Ruby
pattern = /^(?:https?:\/\/)?(?:[a-z]{2,3}\.)?linkedin\.com\/in\/[A-Za-z0-9-]{3,100}\/?$/
text = 'https://www.linkedin.com/in/test-user-123'
matches = text.to_enum(:scan, pattern).map { Regexp.last_match[0] }
p matchesFrequently asked questions
- Why are company pages rejected?
- Company pages use the /company/ path, while personal profiles use /in/. Forms that ask for a personal profile usually want to keep the two apart, so the pattern only accepts /in/.
- Can profile slugs contain underscores?
- LinkedIn public profile URLs use letters, digits and hyphens. Underscores are not allowed in custom slugs, so a link containing one is likely mistyped.
- How do I handle links with ?trk= tracking parameters?
- Remove everything from the question mark onward before testing, or parse the link with the URL API and test only the origin and path. That keeps the stored link clean as well.
Related patterns
- Discord invite link^(?:https?://)?(?:www\.)?(?:discord\.gg|discord(?:app)?\.com/invite)/[A-Za-z0-9-]{2,32}/?$
- Facebook page URL^(?:https?://)?(?:www\.|m\.)?(?:facebook|fb)\.com/[A-Za-z0-9.]{5,50}/?$
- GitHub repository URL^(?:https?://)?(?:www\.)?github\.com/[A-Za-z0-9](?:-?[A-Za-z0-9]){0,38}/[A-Za-z0-9._-]+?(?:\.git)?/?$
- YouTube channel URL^(?:https?://)?(?:www\.)?youtube\.com/(?:@[A-Za-z0-9._-]{3,30}|channel/UC[A-Za-z0-9_-]{22}|c/[A-Za-z0-9_-]+)/?$