Function escapeStringRegexp

  • 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

    Parameters

    • string: string

    Returns string

    import escapeStringRegexp from 'platform-bible-utils';

    const escapedString = escapeStringRegexp('How much $ for a 🦄?');
    //=> 'How much \\$ for a 🦄\\?'

    new RegExp(escapedString);