RepoPilot

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

About sindresorhus/escape-string-regexp · 2 messages · last activity 6/29/2026

Question

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

RepoPilot

Based on the test file, the repository covers specific edge cases around hyphens:

  1. Main character escaping [test.js:L3-L8]: Tests that all RegExp special characters are properly escaped, including the basic set: \ ^ $ * + ? . ( ) | { } [ ]

  2. PCRE compatibility with hyphens [test.js:L10-L14]: Tests that hyphens (-) are escaped using \x2d (hex escape) rather than a simple backslash, ensuring compatibility with PCRE (Perl Compatible Regular Expressions):

    escapeStringRegexp('foo - bar') => 'foo \\x2d bar'
    
  3. Unicode flag compatibility with hyphens [test.js:L16-L20]: Tests that the escaped hyphen works correctly when used with the Unicode flag (u), which has stricter grammar rules. This ensures the escaped string can be safely used in regex patterns with the Unicode flag enabled.

The emphasis on hyphen handling reflects a key design decision in the implementation [index.js:L10]: the hyphen receives special treatment with \x2d escaping rather than a simple backslash, because the simpler form would be disallowed by Unicode patterns' stricter grammar (as noted in the code comments).

FOLLOW_UPS:

  • What other special characters are escaped in the main test?
  • Why does the hyphen need hex escaping specifically?
  • How does the implementation handle non-string inputs?

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.