{"name":"regexgen","version":"1.2.0","description":"Generate regular expressions that match a set of strings","main":"index.js","bin":{"regexgen":"bin/cli.js"},"dependencies":{"jsesc":"^2.3.0","regenerate":"^1.3.2"},"devDependencies":{"mocha":"^3.2.0"},"scripts":{"test":"mocha"},"engines":{"node":">= 6"},"repository":{"type":"git","url":"git+https://github.com/devongovett/regexgen.git"},"keywords":["regex","trie","regular","expression"],"author":{"name":"Devon Govett","email":"devongovett@gmail.com"},"license":"MIT","bugs":{"url":"https://github.com/devongovett/regexgen/issues"},"homepage":"https://github.com/devongovett/regexgen#readme","runkitExample":"const regexgen = require('regexgen');\n\nregexgen(['foobar', 'foobaz', 'foozap', 'fooza']);","gitHead":"9663fbb2f1ff2532b9cc5d1058c6e02dece58e95","_id":"regexgen@1.2.0","_shasum":"41d57e1cb7d045f35cf8d53c7aab54b1d42321c8","_from":".","_npmVersion":"3.9.5","_nodeVersion":"6.2.2","_npmUser":{"name":"devongovett","email":"devongovett@gmail.com"},"dist":{"shasum":"41d57e1cb7d045f35cf8d53c7aab54b1d42321c8","tarball":"http://registry-npm.ywwl.com/regexgen/download/regexgen-1.2.0.tgz","integrity":"sha512-/lUnQqIwgEUd9mlp6aWXq+2nOfbn6+RE65pfIuIXtyNPf+zUuq6axeLXeQ996v7j2FVs8kYRr+9tBZo5lz/FCA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDUjBeOQxYZdMb20lVLS3vBNdrHX/9wa26KnXZ5CKkLdgIgY+D85U7z+yc4fQyLWLKPWt6A5xBP6zxlTeekBNGkdSk="}],"size":6073,"noattachment":false,"key":"/regexgen/-/regexgen-1.2.0.tgz"},"maintainers":[{"name":"devongovett","email":"devongovett@gmail.com"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/regexgen-1.2.0.tgz_1482426929510_0.9818714582361281"},"directories":{},"readme":"# regexgen\n\nGenerates regular expressions that match a set of strings.\n\n## Installation\n\n`regexgen` can be installed using [npm](https://npmjs.com):\n\n```\nnpm install regexgen\n```\n\n## Example\n\nThe simplest use is to simply pass an array of strings to `regexgen`:\n\n```javascript\nconst regexgen = require('regexgen');\n\nregexgen(['foobar', 'foobaz', 'foozap', 'fooza']); // => /foo(?:zap?|ba[rz])/\n```\n\nYou can also use the `Trie` class directly:\n\n```javascript\nconst {Trie} = require('regexgen');\n\nlet t = new Trie;\nt.add('foobar');\nt.add('foobaz');\n\nt.toRegExp(); // => /fooba[rz]/\n```\n\n## CLI\n\n`regexgen` also has a simple CLI to generate regexes using inputs from the command line.\n\n```shell\n$ regexgen\nUsage: regexgen [-gimuy] string1 string2 string3...\n```\n\nThe optional first parameter is the [flags](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp) to add\nto the regex (e.g. `-i` for a case insensitive match).\n\n## ES2015 and Unicode\n\nBy default `regexgen` will output a standard JavaScript regular expression, with Unicode codepoints converted into UCS-2 surrogate pairs.\n\nIf desired, you can request an ES2015-compatible Unicode regular expression by supplying the `-u` flag, which results in those codepoints being retained.\n\n```shell\n$ regexgen 👩 👩‍💻 👩🏻‍💻 👩🏼‍💻 👩🏽‍💻 👩🏾‍💻 👩🏿‍💻\n/\\uD83D\\uDC69(?:(?:\\uD83C[\\uDFFB-\\uDFFF])?\\u200D\\uD83D\\uDCBB)?/\n\n$ regexgen -u 👩 👩‍💻 👩🏻‍💻 👩🏼‍💻 👩🏽‍💻 👩🏾‍💻 👩🏿‍💻\n/\\u{1F469}(?:[\\u{1F3FB}-\\u{1F3FF}]?\\u200D\\u{1F4BB})?/u\n```\n\n\nSuch regular expressions are compatible with current versions of Node, as well as the latest browsers, and may be more transferrable to other languages.\n\n## How does it work?\n\n1. Generate a [Trie](https://en.wikipedia.org/wiki/Trie) containing all of the input strings.\n   This is a tree structure where each edge represents a single character. This removes\n   redundancies at the start of the strings, but common branches further down are not merged.\n\n2. A trie can be seen as a tree-shaped deterministic finite automaton (DFA), so DFA algorithms\n   can be applied. In this case, we apply [Hopcroft's DFA minimization algorithm](https://en.wikipedia.org/wiki/DFA_minimization#Hopcroft.27s_algorithm)\n   to merge the nondistinguishable states.\n\n3. Convert the resulting minimized DFA to a regular expression. This is done using\n   [Brzozowski's algebraic method](http://cs.stackexchange.com/questions/2016/how-to-convert-finite-automata-to-regular-expressions#2392),\n   which is quite elegant. It expresses the DFA as a system of equations which can be solved\n   for a resulting regex. Along the way, some additional optimizations are made, such\n   as hoisting common substrings out of an alternation, and using character class ranges.\n   This produces an an [Abstract Syntax Tree](https://en.wikipedia.org/wiki/Abstract_syntax_tree)\n   (AST) for the regex, which is then converted to a string and compiled to a JavaScript\n   `RegExp` object.\n\n## License\n\nMIT\n","publish_time":1482426931449,"_cnpm_publish_time":1482426931449,"dist-tags":{"latest":"1.3.0"}}