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

Php - Delimiter must not be alphanumeric or backslash -

c# - How to change the "Applies To" field under folder auditing options programatically (.NET) -

c++ - Ambiguity when using boost::assign::list_of to construct a std::vector -