小编Ris*_*han的帖子

字符串匹配Javascript

我想在@符号之后获取字符直到空格字符.

例如.如果我的字符串是 hello @world. some gibberish.@stackoverflow.然后我想得到角色'world'和'stackoverflow'.

这是我一直在尝试的.

var comment = 'hello @world. some gibberish.@stackoverflow';
 var indices = [];
  for (var i = 0; i < comment.length; i++) {
        if (comment[i] === "@") {
            indices.push(i);
            for (var j = 0; j <= i; j++){
               startIndex.push(comment[j]); 
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

我可以得到@和空格的出现然后修剪那部分来获取我的内容但是我想要一个更好的解决方案/建议,没有REGEX.提前致谢.

javascript regex arrays string node.js

5
推荐指数
1
解决办法
65
查看次数

标签 统计

arrays ×1

javascript ×1

node.js ×1

regex ×1

string ×1