Create a gist now

Instantly share code, notes, and snippets.

@PaddeK /test Secret
Created Oct 12, 2017

What would you like to do?
Espruino - Regex replace function test
let img = '720/;66/D65/gf64/wB64/:AH63/+2Af63/g2A63/@;AD63/P.wP62/wPjg62/+Q/PD62/nD:+P:60/:+P#@/j60/l2/vz@P59/:j/+/PAf59/kv/%;wB59/:w2/P(AH59/lv/:/Bwf58/+C2/z@fh59/wJ2/OF/H58/+Uz/#z!+f58/yfn/m/f@59/A/v+Gd/j58/#D/f@#!/P58/k!2/G2f:58/+3/;%2/#58/z3/k3/n58/N2/:z2/+f57/:D2/h/;/#58/yf/:j3/n58/J2/n2/f+P57/:2/:P/)/@58/#2/>f/f/j58/n/+M2/f+P58/P/%#:L/@f57/:2/OT.H/h58/#/;cn:/+X58/z%(:P%/#f58/nzT@fv/l57/A2Ph/x3/H56/wACPk/jf/:f56/P/AOT/l2/x56/.P/@M2/f2/H56/ef/:D/:/f+f55/%+f/j!/#;/@56/v2/:;P2!%/j55/:v2/B./vPn+P55/wP/;2x2+/P#55/+b2/r/z#/+/n55/%2/;H/2n!;.f55/v2/kf/O2f%p55/+j/:%/+Z+/>H55/.P/z2/:n;/If@f53/oH/f2/@Pz+B:AP52/+H/#3/@fn@Pn/P52/z2/v3/@/OQ:gGf52/P/+4/w+YDg/B52/:j/%4/x:AMf/P52/.P/v4/wIAn/+f52/v/:5/w2Af/#52/+2/r/@A2/gAH2/z52/#P;vYH:f/gA3/P52/k+W+x2/D+AD56/P:b/@2/g2Af55/:/zv/+f2/AB56/#+u5/+AP56/z.%3/v/wA57/vlP3/P+AD56/+fE3/+PwEf56/:+D3/+GAx57/#:P4/AHP57/z#5/#:24/Af32/nj4/+f!23/gAD32/nP2/v/j/f22/:f+D32/M/!2+I25/n2/D31/+T.!%@P24/;2/>H31/:P@2/j25/n/vbH31/@fn/w23/f/O/+AvP31/#:/:P22/@fgT2/@+f31/z!+H23/s:cP2/z@32/nfB23/+@Jw3/vL32/IB24/zxnB2/:;n32/g24/f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+AcAfAQC2AHwACAQDxCAHx4AHx2APg8A7/w59A7/60AP5/:987A';
let RgxRLE = {
enc: t => t.replace(/\d/g, i => '()>!@#.%:;'[i]).replace(/([^\d])\1*/g, m => m.length > 1 ? m.length + m[0] : m[0]),
dec: t => t.replace(/(\d+)([^\d])/g, (m, r, c) => new Array(+r + 1).join(c)).replace(/[()>!@#.%:;]/g, i => i.charCodeAt(0) % 10)
};
console.log(RgxRLE.dec(img).length);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment