UpHelix UpHelix - 1 year ago 165
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']

Answer Source
var string = "2d4hk8x37m";
var matches = string.match(/.{2}/g);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download