{"id":13394565,"url":"https://github.com/devongovett/regexgen","last_synced_at":"2025-05-14T02:06:31.531Z","repository":{"id":53746034,"uuid":"76917071","full_name":"devongovett/regexgen","owner":"devongovett","description":"Generate regular expressions that match a set of strings","archived":false,"fork":false,"pushed_at":"2024-02-15T03:01:52.000Z","size":30,"stargazers_count":3416,"open_issues_count":15,"forks_count":101,"subscribers_count":53,"default_branch":"master","last_synced_at":"2025-04-10T19:09:24.932Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://runkit.com/npm/regexgen","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/devongovett.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2016-12-20T02:50:53.000Z","updated_at":"2025-04-10T10:25:06.000Z","dependencies_parsed_at":"2024-04-18T17:58:01.105Z","dependency_job_id":"51fbebc2-5971-4aa6-a544-8426e1806c1f","html_url":"https://github.com/devongovett/regexgen","commit_stats":{"total_commits":34,"total_committers":4,"mean_commits":8.5,"dds":0.1470588235294118,"last_synced_commit":"7ef10aef3a414b10554822cdf6e90389582b1890"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devongovett%2Fregexgen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devongovett%2Fregexgen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devongovett%2Fregexgen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devongovett%2Fregexgen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/devongovett","download_url":"https://codeload.github.com/devongovett/regexgen/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254052701,"owners_count":22006716,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-30T17:01:23.943Z","updated_at":"2025-05-14T02:06:26.502Z","avatar_url":"https://github.com/devongovett.png","language":"JavaScript","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']); // =\u003e /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(); // =\u003e /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","funding_links":[],"categories":["JavaScript","Generators","JavaScript regex libraries","Generator"],"sub_categories":["Regex processors, utilities, and more"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevongovett%2Fregexgen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdevongovett%2Fregexgen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevongovett%2Fregexgen/lists"}