gpt4 book ai didi

javascript - 在 JavaScript 中从字符串中拆分数字

转载 作者:行者123 更新时间:2023-12-01 15:49:36 25 4
gpt4 key购买 nike

这个问题在这里已经有了答案:





Splitting a string into chunks by numeric or alpha character with JavaScript

(3 个回答)


5年前关闭。




我想拆分字符串

'foofo21' 'bar432' 'foobar12345'
进入
['foofo', '21'] ['bar', '432'] ['foobar', '12345']
有没有一种简单的方法可以在 JavaScript 中做到这一点?
请注意字符串部分(例如,foofo 可以是韩语而不是英语)。

最佳答案

第二种解决方案:

var num = "'foofo21".match(/\d+/g);
// num[0] will be 21

var letr = "foofo21".match(/[a-zA-Z]+/g);
/* letr[0] will be foofo.
Now both are separated, and you can make any string as you like. */

关于javascript - 在 JavaScript 中从字符串中拆分数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42827884/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com