Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lorey/social-media-profiles-regexs
:card_index: Extract social media profiles and more with regular expressions
https://github.com/lorey/social-media-profiles-regexs
angellist facebook github hackernews instagram linkedin phone profiles regex regular-expressions scraping skype snapchat social-media-profiles telegram twitter
Last synced: 13 days ago
JSON representation
:card_index: Extract social media profiles and more with regular expressions
- Host: GitHub
- URL: https://github.com/lorey/social-media-profiles-regexs
- Owner: lorey
- Created: 2015-06-24T13:24:14.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2024-01-11T18:33:53.000Z (10 months ago)
- Last Synced: 2024-10-15T08:49:46.570Z (27 days ago)
- Topics: angellist, facebook, github, hackernews, instagram, linkedin, phone, profiles, regex, regular-expressions, scraping, skype, snapchat, social-media-profiles, telegram, twitter
- Language: Python
- Homepage:
- Size: 95.7 KB
- Stars: 605
- Watchers: 26
- Forks: 74
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
Awesome Lists containing this project
README
# Regular Expressions to Match Social Media Profiles
This repository lists regular expressions to match and extract information from URLs of social media profiles.
So if you find a hyperlink to this repo somewhere on the web, i.e. https://github.com/lorey/social-media-profiles-regexs/,
the regular expressions in this repo allow you find out it's a Github link pointing to a repo
as well as extract the username `lorey` and the repo name `social-media-profiles-regexs` from this URL.Features:
- detect the platform a url points to (all major platforms supported)
- extract the information contained within the url (without opening the url, of course)
- extract emails and phone numbers from hyperlinksPlease note:
If you want to extract social media links, depending on your case, there are possibly easier ways:* I've created a [Python library called socials](https://github.com/lorey/socials) that uses these expressions to *automate url detection* and data extraction.
You input the urls, it extracts the type of platform as well as the contained information, e.g. the linked social media profiles.
* There's also a [Socials API](https://github.com/lorey/socials-api) which makes the socials python package available via REST and JSON.
You can use it for free at [socials.karllorey.com](http://socials.karllorey.com/) or deploy it yourself.
You simply input any URL you want to extract profiles from. It will then fetch and return all social media links from the given website.
Try it [here](http://socials.karllorey.com/try).If you're missing a particular platform, please feel free to add it.
Also feel free to add a test that does not work.
An explanation of how this repo works can be found in [CONTRIBUTING.md](CONTRIBUTING.md).
You might also open an issue, of course, I'm happy to help!## Table of Contents
- [angellist](#angellist)
- [crunchbase](#crunchbase)
- [email](#email)
- [facebook](#facebook)
- [github](#github)
- [google plus](#google-plus)
- [hackernews](#hackernews)
- [instagram](#instagram)
- [linkedin](#linkedin)
- [medium](#medium)
- [phone](#phone)
- [reddit](#reddit)
- [skype](#skype)
- [snapchat](#snapchat)
- [stackexchange](#stackexchange)
- [stackexchange network](#stackexchange-network)
- [stackoverflow](#stackoverflow)
- [telegram](#telegram)
- [twitter](#twitter)
- [vimeo](#vimeo)
- [xing](#xing)
- [youtube](#youtube)
- [Monster Regex](#monster-regex)## angellist
### company
```regex
(?:https?:)?\/\/angel\.co\/company\/(?P[A-z0-9_-]+)(?:\/(?P[A-z0-9-]+))?
```Examples:
- https://angel.co/company/twitter
- https://angel.co/company/twitter/culture### job
```regex
(?:https?:)?\/\/angel\.co\/company\/(?P[A-z0-9_-]+)\/jobs\/(?P(?P[0-9]+)-(?P[A-z0-9-]+))
```Examples:
- https://angel.co/company/twitter/jobs/576275-engineering-manager
### user
```regex
(?:https?:)?\/\/angel\.co\/(?Pu|p)\/(?P[A-z0-9_-]+)
```
There are root-level direct links to users, e.g. angel.co/karllorey, that get redirected to these new user links now. Sometimes it's /p/, sometimes it's /u/, haven't figured out why that is...Examples:
- https://angel.co/p/naval
- https://angel.co/u/karllorey## crunchbase
### company
```regex
(?:https?:)?\/\/crunchbase\.com\/organization\/(?P[A-z0-9_-]+)
```Examples:
- http://crunchbase.com/organization/acme-corp
### person
```regex
(?:https?:)?\/\/crunchbase\.com\/person\/(?P[A-z0-9_-]+)
```Examples:
- http://crunchbase.com/person/karl-lorey
### mailto
```regex
(?:mailto:)?(?P[A-z0-9_.+-]+@[A-z0-9_.-]+\.[A-z]+)
```
This matches plain emails and mailto hyperlinks. This regex is intended for scraping and not as a validation. See why: ["Your email validation logic is wrong"](https://www.netmeister.org/blog/email.html).Examples:
- [email protected]
- mailto:[email protected]
- mailto:[email protected]### profile
```regex
(?:https?:)?\/\/(?:www\.)?(?:facebook|fb)\.com\/(?P(?![A-z]+\.php)(?!marketplace|gaming|watch|me|messages|help|search|groups)[A-z0-9_\-\.]+)\/?
```
A profile can be a page, a user profile, or something else. Since Facebook redirects these URLs to all kinds of objects (user, pages, events, and so on), you have to verify that it's actually a user. See https://developers.facebook.com/docs/graph-api/reference/profileExamples:
- http://fb.com/peter_parker-miller
- https://facebook.com/peter.parker
- https://facebook.com/peterparker### profile by id
```regex
(?:https?:)?\/\/(?:www\.)facebook.com\/(?:profile.php\?id=)?(?P[0-9]+)
```Examples:
- https://www.facebook.com/100004123456789
- https://www.facebook.com/profile.php?id=100004123456789## github
### repo
```regex
(?:https?:)?\/\/(?:www\.)?github\.com\/(?P[A-z0-9_-]+)\/(?P[A-z0-9_-]+)\/?
```
Exclude subdomains as these redirect to github pages sometimes.Examples:
- https://github.com/lorey/socials
### user
```regex
(?:https?:)?\/\/(?:www\.)?github\.com\/(?P[A-z0-9_-]+)\/?
```
Exclude subdomains other than `www.` as these redirect to github pages sometimes.Examples:
- https://github.com/lorey/
## google plus
### user id
```regex
(?:https?:)?\/\/plus\.google\.com\/(?P[0-9]{21})
```
Matches profile numbers with exactly 21 digits.Examples:
- https://plus.google.com/111111111111111111111
### username
```regex
(?:https?:)?\/\/plus\.google\.com\/\+(?P[A-z0-9+]+)
```
Matches username.Examples:
- https://plus.google.com/+googleplususername
## hackernews
### item
```regex
(?:https?:)?\/\/news\.ycombinator\.com\/item\?id=(?P[0-9]+)
```
An item can be a post or a direct link to a comment.Examples:
- https://news.ycombinator.com/item?id=23290375
### user
```regex
(?:https?:)?\/\/news\.ycombinator\.com\/user\?id=(?P[A-z0-9_-]+)
```Examples:
- https://news.ycombinator.com/user?id=CamelCaps
- https://news.ycombinator.com/user?id=dash-and-underscore_are-valid
- https://news.ycombinator.com/user?id=lorey### profile
```regex
(?:https?:)?\/\/(?:www\.)?(?:instagram\.com|instagr\.am)\/(?P[A-Za-z0-9_](?:(?:[A-Za-z0-9_]|(?:\.(?!\.))){0,28}(?:[A-Za-z0-9_]))?)
```
The rules:* Matches with one . in them disco.dude but not two .. disco..dude
* Ending period not matched discodude.
* Match underscores _disco__dude
* Max characters of 30 1234567890123456789012345678901234567890Examples:
- https://instagram.com/__disco__dude
- https://instagram.com/disco.dude
- https://www.instagr.am/__disco__dude### company
```regex
(?:https?:)?\/\/(?:[\w]+\.)?linkedin\.com\/(?P(company)|(school))\/(?P[A-z0-9-À-ÿ\.]+)\/?
```
This matches companies and schools. Permalink is an integer id or a slug. The id permalinks redirect to the slug permalinks as soon as one is set. Permalinks can contain special characters. Recently, company links that are actually schools get redirected to newly introduced /school/ permalinks, see the university example below.Examples:
- https://fr.linkedin.com/school/université-grenoble-alpes/
- https://linkedin.com/company/dash-company.io
- https://www.linkedin.com/company/1234567/### post
```regex
(?:https?:)?\/\/(?:[\w]+\.)?linkedin\.com\/feed\/update\/urn:li:activity:(?P[0-9]+)\/?
```
Direct link to a Linkedin post, only contains a post id.Examples:
- https://www.linkedin.com/feed/update/urn:li:activity:6665508550111912345/
### profile
```regex
(?:https?:)?\/\/(?:[\w]+\.)?linkedin\.com\/in\/(?P[\w\-\_À-ÿ%]+)\/?
```
These are the currently used, most-common urls ending in /in/Examples:
- https://de.linkedin.com/in/peter-müller-81a8/
- https://linkedin.com/in/karllorey### profile_pub
```regex
(?:https?:)?\/\/(?:[\w]+\.)?linkedin\.com\/pub\/(?P[A-z0-9_-]+)(?:\/[A-z0-9]+){3}\/?
```
These are old public urls not used anymore, more info at [quora](https://www.quora.com/What-is-the-difference-between-www-linkedin-com-pub-and-www-linkedin-com-in)Examples:
- https://linkedin.com/pub/karllorey/abc/123/be
- https://www.linkedin.com/pub/karllorey/abc/123/be## medium
### post
```regex
(?:https?:)?\/\/medium\.com\/(?:(?:@(?P[A-z0-9]+))|(?P[a-z-]+))\/(?P[a-z0-9\-]+)-(?P[A-z0-9]+)(?:\?.*)?
```Examples:
- https://medium.com/@karllorey/keeping-pandas-dataframes-clean-when-importing-json-348d3439ed67
- https://medium.com/does-exist/some-post-123abc### post of subdomain publication
```regex
(?:https?:)?\/\/(?P(?!www)[a-z-]+)\.medium\.com\/(?P[a-z0-9\-]+)-(?P[A-z0-9]+)(?:\?.*)?
```
Can't match these with the regular post regex as redefinitions of subgroups are not allowed in pythons regex.Examples:
- https://onezero.medium.com/what-facebooks-remote-work-policy-means-for-the-future-of-tech-salaries-everywhere-edf859226b62?source=grid_home------
### user
```regex
(?:https?:)?\/\/medium\.com\/@(?P[A-z0-9]+)(?:\?.*)?
```Examples:
- https://medium.com/@karllorey
### user by id
```regex
(?:https?:)?\/\/medium\.com\/u\/(?P[A-z0-9]+)(?:\?.*)
```
Now redirects to new user profiles. Follow with a head or get request.Examples:
- https://medium.com/u/b3d3d3653c2c?source=post_page-----da92b81b85ef----------------------
## phone
### phone number
```regex
(?:tel|phone|mobile):(?P\+?[0-9. -]+)
```
Should be cleaned afterwards to strip dots, spaces, etc.Examples:
- tel:+49 900 123456
- tel:+49900123456### user
```regex
(?:https?:)?\/\/(?:[a-z]+\.)?reddit\.com\/(?:u(?:ser)?)\/(?P[A-z0-9\-\_]*)\/?
```Examples:
- https://old.reddit.com/user/ar-guetita
- https://reddit.com/u/ar-guetita## skype
### profile
```regex
(?:(?:callto|skype):)(?P[a-z][a-z0-9\.,\-_]{5,31})(?:\?(?:add|call|chat|sendfile|userinfo))?
```
Matches Skype's URLs to add contact, call, chat. More info at [Skype SDK's docs](https://docs.microsoft.com/en-us/skype-sdk/skypeuris/skypeuris).Examples:
- skype:echo123
- skype:echo123?call## snapchat
### profile
```regex
(?:https?:)?\/\/(?:www\.)?snapchat\.com\/add\/(?P[A-z0-9\.\_\-]+)\/?
```Examples:
- https://www.snapchat.com/add/peterparker
## stackexchange
### user
```regex
(?:https?:)?\/\/(?:www\.)?stackexchange\.com\/users\/(?P[0-9]+)\/(?P[A-z0-9-_.]+)\/?
```
This is the meta-platform above stackoverflow, etc. Username can be changed at any time, user_id is persistent.Examples:
- https://stackexchange.com/users/12345/lorey
## stackexchange network
### user
```regex
(?:https?:)?\/\/(?:(?P[a-z]+(?!www))\.)?stackexchange\.com\/users\/(?P[0-9]+)\/(?P[A-z0-9-_.]+)\/?
```
While there are some "named" communities in the stackexchange network like stackoverflow, many only exist as subdomains, i.e. gaming.stackexchange.com. Again, username can be changed at any time, user_id is persistent.Examples:
- https://gaming.stackexchange.com/users/12345/lorey
## stackoverflow
### question
```regex
(?:https?:)?\/\/(?:www\.)?stackoverflow\.com\/questions\/(?P[0-9]+)\/(?P[A-z0-9-_.]+)\/?
```Examples:
- https://stackoverflow.com/questions/12345/how-to-embed
### user
```regex
(?:https?:)?\/\/(?:www\.)?stackoverflow\.com\/users\/(?P[0-9]+)\/(?P[A-z0-9-_.]+)\/?
```
Username can be changed at any time, user_id is persistent.Examples:
- https://stackoverflow.com/users/12345/lorey
## telegram
### profile
```regex
(?:https?:)?\/\/(?:t(?:elegram)?\.me|telegram\.org)\/(?P[a-z0-9\_]{5,32})\/?
```
Matches for t.me, telegram.me and telegram.org.Examples:
- https://t.me/peterparker
### status
```regex
(?:https?:)?\/\/(?:[A-z]+\.)?twitter\.com\/@?(?P[A-z0-9_]+)\/status\/(?P[0-9]+)\/?
```Examples:
- https://twitter.com/karllorey/status/1259924082067374088
### user
```regex
(?:https?:)?\/\/(?:[A-z]+\.)?twitter\.com\/@?(?!home|share|privacy|tos)(?P[A-z0-9_]+)\/?
```
Allowed for usernames are alphanumeric characters and underscores.Examples:
- http://twitter.com/@karllorey
- http://twitter.com/karllorey
- https://twitter.com/karllorey## vimeo
### user
```regex
(?:https?:)?\/\/vimeo\.com\/user(?P[0-9]+)
```Examples:
- https://vimeo.com/user46726126
### video
```regex
(?:https?:)?\/\/(?:(?:www)?vimeo\.com|player.vimeo.com\/video)\/(?P[0-9]+)
```Examples:
- https://player.vimeo.com/video/148751763
- https://vimeo.com/148751763### profile
```regex
(?:https?:)?\/\/(?:www\.)?xing.com\/profile\/(?P[A-z0-9-\_]+)
```
Default slugs are Firstname_Lastname. If several people with the same name exist, a number is appended.Examples:
- https://www.xing.com/profile/Tobias_Zilbersahn5
## youtube
### channel
```regex
(?:https?:)?\/\/(?:[A-z]+\.)?youtube.com\/channel\/(?P[A-z0-9-\_]+)\/?
```Examples:
- https://www.youtube.com/channel/UC3y00Z1zFPc-8Z9xg8ydC-A
- https://www.youtube.com/channel/UCtAh1m085QkEKYNg0j_6r8A### user
```regex
(?:https?:)?\/\/(?:[A-z]+\.)?youtube.com\/user\/(?P[A-z0-9]+)\/?
```Examples:
- https://www.youtube.com/user/JPPGmbH
### video
```regex
(?:https?:)?\/\/(?:(?:www\.)?youtube\.com\/(?:watch\?v=|embed\/)|youtu\.be\/)(?P[A-z0-9\-\_]+)
```
Matches youtube video links like https://www.youtube.com/watch?v=dQw4w9WgXcQ and shortlinks like https://youtu.be/dQw4w9WgXcQExamples:
- https://www.youtube.com/watch?v=dQw4w9WgXcQ
- https://youtu.be/dQw4w9WgXcQ
- https://youtube.com/embed/dQw4w9WgXcQ
- https://youtube.com/watch?v=6_b7RDuLwcI## Monster Regex
If you want to match and extract the data from all urls with one regex, use this monster.
It will return the data for all the platforms above.
The regex subgroups are prefixed with the platform,
e.g. `angellist__company` instead of just `company` in the angellist company regex,
as some regex implementations don't support defining subgroups more than once which would introduce errors if the same subgroup name is used in two or more platforms.```regex
(?P(?:https?:)?\/\/angel\.co\/company\/(?P[A-z0-9_-]+)(?:\/(?P[A-z0-9-]+))?)|(?P(?:https?:)?\/\/angel\.co\/company\/(?P[A-z0-9_-]+)\/jobs\/(?P(?P[0-9]+)-(?P[A-z0-9-]+)))|(?P(?:https?:)?\/\/angel\.co\/(?Pu|p)\/(?P[A-z0-9_-]+))|(?P(?:https?:)?\/\/crunchbase\.com\/organization\/(?P[A-z0-9_-]+))|(?P(?:https?:)?\/\/crunchbase\.com\/person\/(?P[A-z0-9_-]+))|(?P(?:mailto:)?(?P[A-z0-9_.+-]+@[A-z0-9_.-]+\.[A-z]+))|(?P(?:https?:)?\/\/(?:www\.)?(?:facebook|fb)\.com\/(?P(?![A-z]+\.php)(?!marketplace|gaming|watch|me|messages|help|search|groups)[A-z0-9_\-\.]+)\/?)|(?P(?:https?:)?\/\/(?:www\.)facebook.com/(?:profile.php\?id=)?(?P[0-9]+))|(?P(?:https?:)?\/\/(?:www\.)?github\.com\/(?P[A-z0-9_-]+)\/(?P[A-z0-9_-]+)\/?)|(?P(?:https?:)?\/\/(?:www\.)?github\.com\/(?P[A-z0-9_-]+)\/?)|(?P(?:https?:)?\/\/plus\.google\.com\/(?P[0-9]{21}))|(?P(?:https?:)?\/\/plus\.google\.com\/\+(?P[A-z0-9+]+))|(?P(?:https?:)?\/\/news\.ycombinator\.com\/item\?id=(?P[0-9]+))|(?P(?:https?:)?\/\/news\.ycombinator\.com\/user\?id=(?P[A-z0-9_-]+))|(?P(?:https?:)?\/\/(?:www\.)?(?:instagram\.com|instagr\.am)\/(?P[A-Za-z0-9_](?:(?:[A-Za-z0-9_]|(?:\.(?!\.))){0,28}(?:[A-Za-z0-9_]))?))|(?P(?:https?:)?\/\/(?:[\w]+\.)?linkedin\.com\/(?P(company)|(school))\/(?P[A-z0-9-À-ÿ\.]+)\/?)|(?P(?:https?:)?\/\/(?:[\w]+\.)?linkedin\.com\/feed\/update\/urn:li:activity:(?P[0-9]+)\/?)|(?P(?:https?:)?\/\/(?:[\w]+\.)?linkedin\.com\/in\/(?P[\w\-\_À-ÿ%]+)\/?)|(?P(?:https?:)?\/\/(?:[\w]+\.)?linkedin\.com\/pub\/(?P[A-z0-9_-]+)(?:\/[A-z0-9]+){3}\/?)|(?P(?:https?:)?\/\/medium\.com\/(?:(?:@(?P[A-z0-9]+))|(?P[a-z-]+))\/(?P[a-z0-9\-]+)-(?P[A-z0-9]+)(?:\?.*)?)|(?P(?:https?:)?\/\/(?P(?!www)[a-z-]+)\.medium\.com\/(?P[a-z0-9\-]+)-(?P[A-z0-9]+)(?:\?.*)?)|(?P(?:https?:)?\/\/medium\.com\/@(?P[A-z0-9]+)(?:\?.*)?)|(?P(?:https?:)?\/\/medium\.com\/u\/(?P[A-z0-9]+)(?:\?.*))|(?P(?:tel|phone|mobile):(?P\+?[0-9. -]+))|(?P(?:https?:)?\/\/(?:[a-z]+\.)?reddit\.com\/(?:u(?:ser)?)\/(?P[A-z0-9\-\_]*)\/?)|(?P(?:(?:callto|skype):)(?P[a-z][a-z0-9\.,\-_]{5,31})(?:\?(?:add|call|chat|sendfile|userinfo))?)|(?P(?:https?:)?\/\/(?:www\.)?snapchat\.com\/add\/(?P[A-z0-9\.\_\-]+)\/?)|(?P(?:https?:)?\/\/(?:www\.)?stackexchange\.com\/users\/(?P[0-9]+)\/(?P[A-z0-9-_.]+)\/?)|(?P(?:https?:)?\/\/(?:(?P[a-z]+(?!www))\.)?stackexchange\.com\/users\/(?P[0-9]+)\/(?P[A-z0-9-_.]+)\/?)|(?P(?:https?:)?\/\/(?:www\.)?stackoverflow\.com\/questions\/(?P[0-9]+)\/(?P[A-z0-9-_.]+)\/?)|(?P(?:https?:)?\/\/(?:www\.)?stackoverflow\.com\/users\/(?P[0-9]+)\/(?P[A-z0-9-_.]+)\/?)|(?P(?:https?:)?\/\/(?:t(?:elegram)?\.me|telegram\.org)\/(?P[a-z0-9\_]{5,32})\/?)|(?P(?:https?:)?\/\/(?:[A-z]+\.)?twitter\.com\/@?(?P[A-z0-9_]+)\/status\/(?P[0-9]+)\/?)|(?P(?:https?:)?\/\/(?:[A-z]+\.)?twitter\.com\/@?(?!home|share|privacy|tos)(?P[A-z0-9_]+)\/?)|(?P(?:https?:)?\/\/vimeo\.com\/user(?P[0-9]+))|(?P(?:https?:)?\/\/(?:(?:www)?vimeo\.com|player.vimeo.com\/video)\/(?P[0-9]+))|(?P(?:https?:)?\/\/(?:www\.)?xing.com\/profile\/(?P[A-z0-9-\_]+))|(?P(?:https?:)?\/\/(?:[A-z]+\.)?youtube.com\/channel\/(?P[A-z0-9-\_]+)\/?)|(?P(?:https?:)?\/\/(?:[A-z]+\.)?youtube.com\/user\/(?P[A-z0-9]+)\/?)|(?P(?:https?:)?\/\/(?:(?:www\.)?youtube\.com\/(?:watch\?v=|embed\/)|youtu\.be\/)(?P[A-z0-9\-\_]+))```