4 [catastrophic](http://regular-expressions.mobi/catastrophic.html)
5 [exponential-time](http://perlgeek.de/blog-en/perl-tips/in-search-of-an-exponetial-regexp.html)
6 regular expressions by limiting the
7 [star height](https://en.wikipedia.org/wiki/Star_height) to 1
9 WARNING: This module merely *seems* to work given all the catastrophic regular
10 expressions I could find scouring the internet, but I don't have enough of a
11 background in automata to be absolutely sure that this module will catch all
12 exponential-time cases.
14 [![browser support](https://ci.testling.com/substack/safe-regex.png)](https://ci.testling.com/substack/safe-regex)
16 [![build status](https://secure.travis-ci.org/substack/safe-regex.png)](http://travis-ci.org/substack/safe-regex)
21 var safe = require('safe-regex');
22 var regex = process.argv.slice(2).join(' ');
23 console.log(safe(regex));
27 $ node safe.js '(x+x+)+y'
29 $ node safe.js '(beep|boop)*'
31 $ node safe.js '(a+){10}'
33 $ node safe.js '\blocation\s*:[^:\n]+\b(Oakland|San Francisco)\b'
40 var safe = require('safe-regex')
43 ## var ok = safe(re, opts={})
45 Return a boolean `ok` whether or not the regex `re` is safe and not possibly
48 `re` can be a `RegExp` object or just a string.
50 If the `re` is a string and is an invalid regex, returns `false`.
52 * `opts.limit` - maximum number of allowed repetitions in the entire regex.
57 With [npm](https://npmjs.org) do:
60 npm install safe-regex