Skip to content

Commit ec45c70

Browse files
authored
Escape - in a way that’s compatible with PCRE (#23)
1 parent d248d82 commit ec45c70

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ module.exports = string => {
99
// 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.
1010
return string
1111
.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&')
12-
.replace(/-/g, '\\u002d');
12+
.replace(/-/g, '\\x2d');
1313
};

test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ test('main', t => {
88
);
99
});
1010

11-
test('escapes `-`', t => {
11+
test('escapes `-` in a way compatible with PCRE', t => {
1212
t.is(
1313
escapeStringRegexp('foo - bar'),
14-
'foo \\u002d bar'
14+
'foo \\x2d bar'
1515
);
1616
});
1717

0 commit comments

Comments
 (0)