Split a string to groups of 2 chars using split?

后端 未结 3 793
长情又很酷
长情又很酷 2020-12-10 04:19

I have this simple string :

\"a1a2a3\"

Is there any regex expression which can be used with split command so it will split the str

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-10 05:06

    I'm not sure what are all possible format of input string, but I assume it's some letter followed by some numbers.

    If so you could try:

    var str = 'abc123d56efg8t5'
    var res = str.split(/([a-z]+[0-9]+)/).filter(Boolean);
    

    output:

    ["abc123", "d56", "efg8", "t5"]
    

提交回复
热议问题