我有这个字符串:
Hey I love #apple and #orange and also #banana
Run Code Online (Sandbox Code Playgroud)
我想提取以#符号开头的每个单词.
目前我正在使用此代码实现它:
var last = 0;
var n = 0;
var str = "Hey I love #apple and #orange and also #banana";
do{
n = str.indexOf("#", last);
if(n != -1){
//The code found the # char at position 'n'
last = n+1; //saving the last found position for next loop
//I'm using this to find the end of the word
var suffixArr = [' ', '#'];
var e …Run Code Online (Sandbox Code Playgroud)