UpHelix UpHelix - 1 year ago 85
Javascript Question

Js RegExp every other character

I have random strings that are similar to this:


or whatever. I need to split it at every other character.

To split it at every character its simply:


But i need every other character so the array would be like this:

['2d', '4h', 'k8', 'x3', '7m']

var string = "2d4hk8x37m";
var matches = string.match(/.{2}/g);