相关疑难解决方法(0)

Javascript:从字符串中的特定字符开始提取单词

我有这个字符串:

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)

javascript regex string

2
推荐指数
1
解决办法
5485
查看次数

标签 统计

javascript ×1

regex ×1

string ×1