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})(\]?)$/
String | Match |
---|---|
foo@bar.com | ✓ |
lol.foo@bar.com | ✓ |
foo@bar | ✗ |
/^(((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
String | Match |
---|---|
https://soundcloud.com/geierre/only-tonight | ✓ |
/^https?:\/\/(?:www\.)?deezer\.com\/(track|album|playlist)\/(\d+)$/
/^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 | ✓ |
/^https?:\/\/(?:www\.)?vimeo\.com.+?(\d+).*$/i
String | Match |
---|---|
https://vimeo.com/58165438 | ✓ |
http://vimeo.com/58165438 | ✓ |
/^https?:\/\/(?:www\.)?(?:dai\.ly\/|dailymotion\.com\/(?:.+?video=|(?:video|hub)\/))([a-z0-9]+)$/i
String | Match |
---|---|
http://www.dailymotion.com/video/x3pu5i0 | ✓ |
/^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
String | Match |
---|---|
http://i.imgur.com/w59wsnu.gifv | ✓ |
/^https?:\/\/(www\.)?github\.com\/[a-z0-9]+$/i
String | Match |
---|---|
https://github.com/OpenCode | ✓ |
/^https?:\/\/twitter.com\/[a-z0-9_]+\/status\/[0-9]+$/i
String | Match |
---|---|
https://twitter.com/_opencode/status/690479102978035712 | ✓ |
/<!\[CDATA\[(.*)\]\]>/