ECMAScript proposed RegExp.escape.
npm install regexp-escape-x href="https://travis-ci.org/Xotic750/regexp-escape-x"
title="Travis status"> src="https://travis-ci.org/Xotic750/regexp-escape-x.svg?branch=master"
alt="Travis status" height="18">
href="https://david-dm.org/Xotic750/regexp-escape-x"
title="Dependency status"> alt="Dependency status" height="18"/>
href="https://david-dm.org/Xotic750/regexp-escape-x?type=dev"
title="devDependency status"> alt="devDependency status" height="18"/>
href="https://badge.fury.io/js/regexp-escape-x"
title="npm version"> alt="npm version" height="18">
href="https://www.jsdelivr.com/package/npm/regexp-escape-x"
title="jsDelivr hits"> alt="jsDelivr hits" height="18">
href="https://bettercodehub.com/results/Xotic750/regexp-escape-x"
title="bettercodehub score"> alt="bettercodehub score" height="18">
href="https://coveralls.io/github/Xotic750/regexp-escape-x?branch=master"
title="Coverage Status"> alt="Coverage Status" height="18">
ECMAScript proposed RegExp.escape.
See: RegExp.escape
Method to safely escape RegExp special tokens for use in new RegExp.
Kind: Exported function
Returns: string - The escaped string.
Throws:
- TypeError If string is null or undefined or not coercible.
| Param | Type | Description |
| ------ | ------------------- | ------------------------- |
| string | string | The string to be escaped. |
Example
``js
import regexpEscape from 'regexp-escape-x';
const str = 'hello. how are you?';
const regex = new RegExp(regexpEscape(str), 'g');
console.log(String(regex)); // '/hello\. how are you\?/g'
``