Created
May 25, 2019 19:52
-
-
Save yairEO/e5b3673d794bb546c721125de818e115 to your computer and use it in GitHub Desktop.
Get parts of string between certain characters
This file contains 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
var s = "@cartman ,[[kyle]] do not know:[[homer simpson]]"; | |
var collect = false; | |
var t; | |
for( let i = 0; i < s.length; i++ ){ | |
if( s[i] == '[' && s[i] == s[i+1]){ | |
collect = true; | |
i = i + 1; | |
continue; | |
} | |
if( s[i] == ']' && s[i] == s[i+1]){ | |
collect = false; | |
console.log( t ); | |
t = ""; | |
} | |
else if (collect) | |
t += s[i]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Parts including matched characters: