如何用非数字的任何内容拆分字符串

how to split a string with anything that is not a number

字符串输入:

“12 个苹果、3 个橙子、10 个葡萄”

解法:

let arr= inputString.split(" ");

要解决的问题:

我将如何拆分任何不是数字的东西?

字符串示例:

我认为可行的方法:

arr= inputString.split("isNaN");

您可以使用正则表达式:

const str = '12apples,3oranges,10grapes';

const splitString = str.match(/(?:\d+\.)?\d+/g);

console.log(splitString);


let str = "12apples,3oranges,10grapes"

console.log(str.split(/[^\d]/g).filter(e => e))

str = "there are some (12) digits 5566 in this 770 string 239"

console.log(str.split(/[^\d]/g). filter(e => e))

str="33+22"

console.log(str.split(/[^\d]/g). filter(e => e))

let str = "12 apples, 3 oranges, 10 grapes"
let arr = str.match(/\d+(.\d+)?/g)
console.log(arr)