Node.js 单词和空格之间的JS子字符串

Node.js 单词和空格之间的JS子字符串,node.js,substring,indexof,discord.js,lastindexof,Node.js,Substring,Indexof,Discord.js,Lastindexof,我有一根像 “用户名234234一些文本” 我想把他们分出来 “用户名” “234234” 和“一些文本” 我尝试使用split和substring,但没有找到第二个空格,通常返回空白文本 多谢各位 尝试使用此正则表达式/(?。+)(?[0-9]+)(?。+)/g const testString=“用户名234234一些文本”; 常数reg=/(?。+)(?[0-9]+)(?。+)/g; const matches=reg.exec(myString); console.log(匹配[0]);

我有一根像

“用户名234234一些文本”

我想把他们分出来

“用户名”

“234234”

和“一些文本”

我尝试使用split和substring,但没有找到第二个空格,通常返回空白文本


多谢各位

尝试使用此正则表达式
/(?。+)(?[0-9]+)(?。+)/g

const testString=“用户名234234一些文本”;
常数reg=/(?。+)(?[0-9]+)(?。+)/g;
const matches=reg.exec(myString);
console.log(匹配[0]);//用户名
console.log(匹配[1]);//234234
console.log(匹配[2]);//一些文本
希望这有助于:

let str = "username 234234 some text";
let arr = str.split(" ");
let username = arr[0];
let num = arr[1];
let otherText = arr.slice(2).join(" ");

以下是discord.js项目的代码,因为您使用了标记“discord.js”:


你能告诉我们你做了什么吗?
let str = "username 234234 some text";
let arr = str.split(" ");
let username = arr[0];
let num = arr[1];
let otherText = arr.slice(2).join(" ");
const content = message.content.split(" ");
console.log(content) // will log the entire message

content = content.slice(0, 1);
console.log(content) // will log you the username

content = content.slice(1, 2);
console.log(content) // will log you the number

content = content.slice(2);
console.log(content) // will log you the text