Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/xotic750/regexp-escape-x

regexpEscape module.
https://github.com/xotic750/regexp-escape-x

browser ecmascript nodejs regexp-escape

Last synced: 4 days ago
JSON representation

regexpEscape module.

Awesome Lists containing this project

README

        


Travis status


Dependency status


devDependency status


npm version


jsDelivr hits


bettercodehub score


Coverage Status

## regexp-escape-x

ECMAScript proposed RegExp.escape.

**See**: [RegExp.escape](https://github.com/benjamingr/RegExp.escape)

### `module.exports(string)` ⇒ string

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'
```