The data is actually coming from a websocket and I want to extract the 1234
from it...
var data = 'TEST|1234\0'
console.log(data);
Output:
TEST|1234
As a result regex isn't working as expected either.
var regex = /\|(.*?)\\/;
var re = new RegExp(regex, "g");
var extractedNumber = msg.match(re);
console.log(extractedNumber);
Output:
null
But if I change the regex to see what is happening I see that \0
is becoming \u0000
var regex = /\|(.*)/;
var re = new RegExp(regex, "g");
var extractedNumber = msg.match(re);
console.log(extractedNumber);
Output:
[ '|1234\u0000' ]
This answer says that \u0000
would be the unicode representation of a character with ASCII code 0.