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.
All credit to escape-string-regexp - this function is simply copied directly from there to allow a common js export
escape-string-regexp
import escapeStringRegexp from 'platform-bible-utils'; const escapedString = escapeStringRegexp('How much $ for a 🦄?'); //=> 'How much \\$ for a 🦄\\?' new RegExp(escapedString); Copy
import escapeStringRegexp from 'platform-bible-utils'; const escapedString = escapeStringRegexp('How much $ for a 🦄?'); //=> 'How much \\$ for a 🦄\\?' new RegExp(escapedString);
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.
All credit to
escape-string-regexp
- this function is simply copied directly from there to allow a common js export