【发布时间】:2021-08-13 08:35:04
【问题描述】:
我有一个类似的字符串:$m-set 88829828277 very good he is。从这个字符串我想得到第二个空格之后的部分。即,我想得到:very good he is。
我尝试使用split(" ")[2],但它只给出一个词:very。
非常感谢任何帮助!
谢谢!
【问题讨论】:
标签: javascript string
我有一个类似的字符串:$m-set 88829828277 very good he is。从这个字符串我想得到第二个空格之后的部分。即,我想得到:very good he is。
我尝试使用split(" ")[2],但它只给出一个词:very。
非常感谢任何帮助!
谢谢!
【问题讨论】:
标签: javascript string
虽然你可以拆分和加入:
const input = '$m-set 88829828277 very good he is';
const splits = input.split(' ');
const output = splits.slice(2).join(' ');
console.log(output);
你也可以使用正则表达式:
const input = '$m-set 88829828277 very good he is';
const output = input.match(/\S+ \S+ (.+)/)[1];
console.log(output);
(.+) 将所有内容放在捕获组中第二个空格之后,[1] 从匹配项中访问捕获组。
【讨论】: