gpt4 book ai didi

javascript - 正则表达式拆分为大写和第一个数字

转载 作者:搜寻专家 更新时间:2023-11-01 04:52:46 25 4
gpt4 key购买 nike

我需要将字符串 "thisIs12MyString" 拆分成一个数组,看起来像 [ "this", "Is", "12", "My", "String"]

到目前为止,我已经知道 "thisIs12MyString".split(/(?=[A-Z0-9])/) 但它会拆分每个数字并给出数组 [“这个”、"is"、“1”、“2”、“我的”、“字符串”]

所以在单词中我需要将字符串拆分为大写字母和前面没有其他数字的数字。

最佳答案

你在找这个吗?

"thisIs12MyString".match(/[A-Z]?[a-z]+|[0-9]+/g)

返回

["this", "Is", "12", "My", "String"]

关于javascript - 正则表达式拆分为大写和第一个数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9453415/

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