Awesome Regex (Regular Expressions) 
A curated list of awesome Regex (Regular Expressions) ready to use
Test regex on https://regex101.com/#pcre
Table of Content
- Awesome Regex
- Information technology
- Hex color
- IP Address
- MAC Address
- Mail
- URL
- Spotify track
- Spotify playlist
- Soundcloud
- Deezer track/album/playlist
- Youtube
- Vimeo
- Dailymotion
- Facebook
- NERDZCrush
- Imgur
- GitHub
- Twitter status
- Text manipulation
Information technology
Hex color
/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/
| String |
Match |
| #C0FF33 |
✓ |
| #000000 |
✓ |
| #fff |
✓ |
| #ffffff |
✓ |
| #FFFFFF |
✓ |
IP Address
/^((?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))*$/
| String |
Match |
| 192.168.1.1 |
✓ |
| 255.255.255.0 |
✓ |
| 8.8.8.8 |
✓ |
MAC Address
/^(?:[0-9a-f]{2}[\-:]?){6}(?<![\-:])$/i
| String |
Match |
| AA:BB:CC:DD:EE:FF |
✓ |
| AA-BB-CC-DD-EE-FF |
✓ |
| AA:BB-CC:DD-EE:FF |
✓ |
| AABBCCDDEEFF |
✓ |
| AA.BB.CC.DD.EE.FF |
✗ |
| AA-BB-CC-DD-EE-GG |
✗ |
| AA:BB:CC:DD:EE:FF: |
✗ |
| AA:BB:CC:DD:EE:FF- |
✗ |
Mail
/^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/
URL
/^(((http|https|ftp):\/\/)?([[a-zA-Z0-9]\-\.])+(\.)([[a-zA-Z0-9]]){2,4}([[a-zA-Z0-9]\/+=%&_\.~?\-]*))*$/
Spotify track
/^https?:\/\/(?:open|play)\.spotify\.com\/track\/[\w\d]+$/i
Spotify playlist
/^https?:\/\/(?:open|play)\.spotify\.com\/user\/([\w\d]+)\/playlist\/[\w\d]+$/i
Soundcloud
/^https?:\/\/soundcloud\.com\/\S+\/\S+$/i
| String |
Match |
| https://soundcloud.com/geierre/only-tonight |
✓ |
Deezer track/album/playlist
/^https?:\/\/(?:www\.)?deezer\.com\/(track|album|playlist)\/(\d+)$/
Youtube
/^https?:\/\/(?:(?:www|m)\.)?(?:youtube\.com\/watch(?:\?v=|\?.+?&v=)|youtu\.be\/)([a-z0-9_-]+)$/i
| String |
Match |
| http://www.youtube.com/watch?v=dbB-mICjkQM |
✓ |
| https://www.youtube.com/watch?v=dbB-mICjkQM |
✓ |
| https://m.youtube.com/watch?v=dbB-mICjkQM |
✓ |
| https://youtu.be/dbB-mICjkQM |
✓ |
Vimeo
/^https?:\/\/(?:www\.)?vimeo\.com.+?(\d+).*$/i
| String |
Match |
| https://vimeo.com/58165438 |
✓ |
| http://vimeo.com/58165438 |
✓ |
Dailymotion
/^https?:\/\/(?:www\.)?(?:dai\.ly\/|dailymotion\.com\/(?:.+?video=|(?:video|hub)\/))([a-z0-9]+)$/i
| String |
Match |
| http://www.dailymotion.com/video/x3pu5i0 |
✓ |
Facebook photo / video
/^https?:\/\/(?:www\.)?facebook\.com\/(?:(?:photo|video)\.php(?:\?v=|\?.+?&v=)|[a-z0-9._-]+\/videos\/)(\d+)\/?$/i
NERDZCrush
/^https?:\/\/(?:cdn\.)?media\.nerdz\.eu\/([a-z0-9_-]{12})(?:|\.[a-z0-9]{2,4})$/i
Imgur
/^https?:\/\/(?:www\.)?(?:i\.)?imgur\.com\/([a-z0-9_-]+)\.(?:gifv|webm)$/i
| String |
Match |
| http://i.imgur.com/w59wsnu.gifv |
✓ |
GitHub profile / organization
/^https?:\/\/(www\.)?github\.com\/[a-z0-9]+$/i
| String |
Match |
| https://github.com/OpenCode |
✓ |
Twitter status
/^https?:\/\/twitter.com\/[a-z0-9_]+\/status\/[0-9]+$/i
| String |
Match |
| https://twitter.com/_opencode/status/690479102978035712 |
✓ |
Text manipulation
Remove CDATA tags
/<!\[CDATA\[(.*)\]\]>/