quotemeta
Version:
escape regular expression characters
53 lines (35 loc) • 971 B
Markdown
escape regular expression metacharacters
This module is like
[](http://perldoc.perl.org/functions/quotemeta.html)
without the part about `\Q...\E`.
[](http://travis-ci.org/substack/quotemeta)
[](http://ci.testling.com/substack/quotemeta)
``` js
var quotemeta = require('quotemeta');
var query = new RegExp('\\d ' + quotemeta('node.js'));
var filter = function (x) { return query.test(x) };
var xs = [
'0 node^js y',
'1 node_js x',
'2 node.js 5',
'3 beep z',
'X node.js Y',
'4 boop w'
];
console.dir(xs.filter(filter));
```
``` js
var quotemeta = require('quotemeta')
```
Return `string` with metacharacters escaped with `\`s.
With [npm](https://npmjs.org) do:
```
npm install quotemeta
```
MIT