Created
July 5, 2018 06:56
-
-
Save ozrabal/4d4e0a94cf2fb27a74149c029c095fe9 to your computer and use it in GitHub Desktop.
regex for slack style emoji shortcode
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const regex = /:[^:\s]*(?:::[^:\s]*)*:/g; | |
| const str = `:any-non-whitespace: | |
| :kudos: | |
| :text1:sample2: | |
| :@(1@#\$@SD: :s: | |
| :nospace::inbetween: because there are 2 colons in the middle | |
| :nospace:middle:nospace:`; | |
| let m; | |
| while ((m = regex.exec(str)) !== null) { | |
| // This is necessary to avoid infinite loops with zero-width matches | |
| if (m.index === regex.lastIndex) { | |
| regex.lastIndex++; | |
| } | |
| // The result can be accessed through the `m`-variable. | |
| m.forEach((match, groupIndex) => { | |
| console.log(`Found match, group ${groupIndex}: ${match}`); | |
| }); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment