tc39 / proposal-regex-escaping

Proposal for investigating RegExp escaping for the ECMAScript standard
http://tc39.es/proposal-regex-escaping/
Creative Commons Zero v1.0 Universal
363 stars 32 forks source link

Escaping of first decimal digits in the current form - is this something what we expect? #62

Closed zloirock closed 11 months ago

zloirock commented 11 months ago

If I understand correctly, with the current spec draft logic, we have:

const string = '40';
const escaped = RegExp.escape(string); // => '\\x40'
const re = new RegExp(escaped); // => /\x40/

re.test('40'); // => false
re.test('@'); // => true

image

Is this expected behavior?

zloirock commented 11 months ago

It seems it should be something like \x340.

jridgewell commented 11 months ago

You're right, we should be hex encoding the the digit in this case.

ljharb commented 11 months ago

Yes, the intention is to hex encode.