{"name":"regexgen","version":"1.2.4","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":"3a3f8ae169e73b8ca4bca3935099b2ce0f34f81a","_id":"regexgen@1.2.4","_shasum":"4464af18f2d567718f2ddd43e288cee3ea1446fb","_from":".","_npmVersion":"3.10.9","_nodeVersion":"6.9.2","_npmUser":{"name":"devongovett","email":"devongovett@gmail.com"},"dist":{"shasum":"4464af18f2d567718f2ddd43e288cee3ea1446fb","tarball":"http://registry-npm.ywwl.com/regexgen/download/regexgen-1.2.4.tgz","integrity":"sha512-56B4W8SVDx9SRhZUzJAGthivItE1Og/61dvlcfHEzRALAmkWdW7s2Gd3uClpP0UuZhYTAzt91JR3I9bT193fPQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIEmYdkpkT92YrxsMeRMqP97wS1w6DP8DWJpPisxJXx91AiEA5i3fw8VKIPaewrBk6kjChHxFLSLPNIjfyZPwmpOYb3s="}],"size":6782,"noattachment":false,"key":"/regexgen/-/regexgen-1.2.4.tgz"},"maintainers":[{"name":"devongovett","email":"devongovett@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/regexgen-1.2.4.tgz_1498934227015_0.8220122598577291"},"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":1498934227103,"_cnpm_publish_time":1498934227103,"dist-tags":{"latest":"1.3.0"}}