Awesome Regex (Regular Expressions)
A curated list of awesome Regex (Regular Expressions) ready to use
Test regex on https://regex101.com/#pcre
/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/
String |
Match |
#C0FF33 |
✓ |
#000000 |
✓ |
#fff |
✓ |
#ffffff |
✓ |
#FFFFFF |
✓ |
/^((?:(?: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 |
✓ |
/^(?:[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- |
✗ |
/^([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})(\]?)$/
/^(((http|https|ftp):\/\/)?([[a-zA-Z0-9]\-\.])+(\.)([[a-zA-Z0-9]]){2,4}([[a-zA-Z0-9]\/+=%&_\.~?\-]*))*$/
/^https?:\/\/(?:open|play)\.spotify\.com\/track\/[\w\d]+$/i
/^https?:\/\/(?:open|play)\.spotify\.com\/user\/([\w\d]+)\/playlist\/[\w\d]+$/i
/^https?:\/\/soundcloud\.com\/\S+\/\S+$/i
Deezer track/album/playlist
/^https?:\/\/(?:www\.)?deezer\.com\/(track|album|playlist)\/(\d+)$/
/^https?:\/\/(?:(?:www|m)\.)?(?:youtube\.com\/watch(?:\?v=|\?.+?&v=)|youtu\.be\/)([a-z0-9_-]+)$/i
/^https?:\/\/(?:www\.)?vimeo\.com.+?(\d+).*$/i
/^https?:\/\/(?:www\.)?(?:dai\.ly\/|dailymotion\.com\/(?:.+?video=|(?:video|hub)\/))([a-z0-9]+)$/i
/^https?:\/\/(?:www\.)?facebook\.com\/(?:(?:photo|video)\.php(?:\?v=|\?.+?&v=)|[a-z0-9._-]+\/videos\/)(\d+)\/?$/i
/^https?:\/\/(?:cdn\.)?media\.nerdz\.eu\/([a-z0-9_-]{12})(?:|\.[a-z0-9]{2,4})$/i
/^https?:\/\/(?:www\.)?(?:i\.)?imgur\.com\/([a-z0-9_-]+)\.(?:gifv|webm)$/i
GitHub profile / organization
/^https?:\/\/(www\.)?github\.com\/[a-z0-9]+$/i
Twitter status
/^https?:\/\/twitter.com\/[a-z0-9_]+\/status\/[0-9]+$/i