diff --git a/index.js b/index.js index e5bb9db..387c561 100644 --- a/index.js +++ b/index.js @@ -9,5 +9,5 @@ module.exports = string => { // Use a simple backslash escape when it’s always valid, and a \unnnn escape when the simpler form would be disallowed by Unicode patterns’ stricter grammar. return string .replace(/[|\\{}()[\]^$+*?.]/g, '\\$&') - .replace(/-/g, '\\u002d'); + .replace(/-/g, '\\x2d'); }; diff --git a/package.json b/package.json index 5f313f2..c6eb4a9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "escape-string-regexp", - "version": "3.0.0", + "version": "4.0.0", "description": "Escape RegExp special characters", "license": "MIT", "repository": "sindresorhus/escape-string-regexp", diff --git a/test.js b/test.js index fe5f549..e50f40b 100644 --- a/test.js +++ b/test.js @@ -8,10 +8,10 @@ test('main', t => { ); }); -test('escapes `-`', t => { +test('escapes `-` in a way compatible with PCRE', t => { t.is( escapeStringRegexp('foo - bar'), - 'foo \\u002d bar' + 'foo \\x2d bar' ); });