我想在@符号之后获取字符直到空格字符.
例如.如果我的字符串是 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.提前致谢.