Friday, 12 May 2017

JavaScript RegExp matches binary data

I'm using RegExp to match a series of bytes other than 0x1b from the sequence [0xcb, 0x98, 0x1b] :

var r = /[^\x1b]+/g;
r.exec(new Buffer([0xcb, 0x98, 0x1b]));
console.log(r.lastIndex);

I expected that the pattern would match 0xcb, 0x98 and r.lastIndex == 2, but it matches 0xcb only and r.lastIndex == 1. Is that a bug or something?



via Chris Lin

No comments:

Post a Comment