Split a string to groups of 2 chars using split?

后端 未结 3 795
长情又很酷
长情又很酷 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 04:52

    I already answered this in chat. You really should be using String.prototype.match.

    Can be done with split? Technically, yes. You can split it by /(..)/ and then filter out the blank strings.

    "a1a2a3".split(/(..)/).filter(function(a){
        return a !== '';
    });
    

提交回复
热议问题