RepoPilot

What edge cases are covered in the tests, especially around hyphens?

About sindresorhus/escape-string-regexp · 2 messages · last activity 7/13/2026

Question

What edge cases are covered in the tests, especially around hyphens?

RepoPilot

The tests cover two specific edge cases related to hyphens:

  1. PCRE Compatibility [test.js:L10-L14]: The test 'escapes - in a way compatible with PCRE' verifies that hyphens are escaped using the hex escape sequence \x2d rather than a simple backslash escape. This is important because in PCRE (Perl Compatible Regular Expressions), a hyphen can have special meaning in certain contexts.

  2. Unicode Flag Compatibility [test.js:L16-L21]: The test 'escapes - in a way compatible with the Unicode flag' ensures that the escaped hyphen works correctly when using the Unicode (u) flag in a RegExp. This validates that \x2d is compatible with Unicode patterns.

The main test [test.js:L3-L8] also covers the general case of escaping all RegExp special characters (\ ^ $ * + ? . ( ) | { } [ ]) with simple backslash escapes.

The reason for the special hyphen handling is explained in the implementation [index.js:L6-L10]. The code uses:

  • .replace(/[|\\{}()[\]^$+*?.]/g, '\\$&') for standard special characters
  • .replace(/-/g, '\\x2d') specifically for hyphens to ensure compatibility with both PCRE and Unicode patterns

FOLLOW_UPS:

  • Why does the hyphen need special \x2d escaping?
  • Does this library handle all RegExp special characters?
  • What does the README say about edge case placements?

Public Q&A. Generated by RepoPilot from the actual source of sindresorhus/escape-string-regexp. AI answers can be incomplete or stale — verify before relying on them.