Skip to content

Commit

Permalink
Escape - in a way that’s compatible with PCRE (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
charmander committed Apr 23, 2020
1 parent d248d82 commit ec45c70
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion index.js
Expand Up @@ -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.

This comment has been minimized.

Copy link
@denilsonsa

denilsonsa Jun 9, 2020

Forgot to update the comment from \unnnn to \xnn.

This comment has been minimized.

Copy link
@sindresorhus

sindresorhus Jun 9, 2020

Owner
return string
.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&')
.replace(/-/g, '\\u002d');
.replace(/-/g, '\\x2d');
};
4 changes: 2 additions & 2 deletions test.js
Expand Up @@ -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'
);
});

Expand Down

0 comments on commit ec45c70

Please sign in to comment.