javascript - Dynamic regular expression -


trying make expression dynamic. can split string in equal chunks.

var keyparts = key.match(/.{1,4}/g);

var keyparts = key.match(/.{rangea,rangeb}/g);

so want make range, trying put in new regexp() w/o positive results.

try this:

var re = new regexp(".{" + rangea + "," + rangeb + "}", "g"); var keyparts = key.match(re); 

demo: http://jsfiddle.net/bzkaq/

in demo, notice how when change length of key between ranges, match string.

reference:


Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -