@ryusei/code
Version:
<div align="center"> <a href="https://code.ryuseijs.com"> <img alt="RyuseiCode" src="https://code.ryuseijs.com/images/svg/logo.svg" width="70"> </a>
11 lines (10 loc) • 304 B
text/typescript
/**
* Escapes string for the RegExp source.
*
* @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions
*
* @param string - A string to escape.
*/
export function escapeRegExp( string: string ): string {
return string.replace( /[.*+\-?^${}()|[\]\\]/g, '\\$&' );
}