我正在尝试为测验应用拆分技术首字母缩略词
Array.from('CAPTCHA')
Gives me: ['C','A','P','T','C','H','A']
如果首字母缩略词只是字母,效果很好
但是……
Array.from('AES256')
Gives me: ['A', 'E', 'S', '2', '5', '6']
我想将首字母缩略词中的任何数字组放在一起
e.g. ['A', 'E', 'S', '256']
关于如何完成这项工作有什么建议吗?
正则表达式?
最佳答案
您可以使用 regular expression与 String.match()
:
const pattern = /[^0-9]|[0-9]+/g
console.log('CAPTCHA'.match(pattern))
console.log('AES256'.match(pattern))
关于javascript - 用字母和数字组拆分字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58566307/