-
-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This enables you to escape a string that is inserted into a regex, for example, into a character class. Fixes #9
- Loading branch information
1 parent
ea98098
commit e76291d
Showing
4 changed files
with
17 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,18 @@ | ||
/** | ||
Escape RegExp special characters. | ||
You can also use this to escape a string that is inserted into the middle of a regex, for example, into a character class. | ||
@example | ||
``` | ||
import escapeStringRegexp = require('escape-string-regexp'); | ||
const escapedString = escapeStringRegexp('how much $ for a 🦄?'); | ||
//=> 'how much \\$ for a 🦄\\?' | ||
const escapedString = escapeStringRegexp('How much $ for a 🦄?'); | ||
//=> 'How much \\$ for a 🦄\\?' | ||
new RegExp(escapedString); | ||
``` | ||
*/ | ||
declare const escapeStringRegexp: (str: string) => string; | ||
declare const escapeStringRegexp: (string: string) => string; | ||
|
||
export = escapeStringRegexp; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters