{"id":16747904,"url":"https://github.com/amake/regexgen-ruby","last_synced_at":"2025-07-24T09:36:07.553Z","repository":{"id":56891664,"uuid":"286484388","full_name":"amake/regexgen-ruby","owner":"amake","description":"Generate regular expressions that match a set of strings","archived":false,"fork":false,"pushed_at":"2023-02-27T12:04:29.000Z","size":66,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-22T20:19:05.896Z","etag":null,"topics":["regex","ruby"],"latest_commit_sha":null,"homepage":"https://rubygems.org/gems/regexgen","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/amake.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","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,"publiccode":null,"codemeta":null},"funding":{"github":"amake"}},"created_at":"2020-08-10T13:34:29.000Z","updated_at":"2021-11-25T23:01:57.000Z","dependencies_parsed_at":"2025-01-22T15:42:23.323Z","dependency_job_id":null,"html_url":"https://github.com/amake/regexgen-ruby","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amake%2Fregexgen-ruby","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amake%2Fregexgen-ruby/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amake%2Fregexgen-ruby/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amake%2Fregexgen-ruby/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/amake","download_url":"https://codeload.github.com/amake/regexgen-ruby/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243818205,"owners_count":20352629,"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":["regex","ruby"],"created_at":"2024-10-13T02:11:14.314Z","updated_at":"2025-03-16T03:10:42.969Z","avatar_url":"https://github.com/amake.png","language":"Ruby","funding_links":["https://github.com/sponsors/amake"],"categories":[],"sub_categories":[],"readme":"# regexgen\n\nGenerate regular expressions that match a set of strings.\n\nThis is a Ruby port of [@devongovett](https://github.com/devongovett/regexgen)'s\nJavaScript [regexgen](https://github.com/devongovett/regexgen) package.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'regexgen'\n```\n\nAnd then execute:\n\n    $ bundle install\n\nOr install it yourself as:\n\n    $ gem install regexgen\n\n## Usage\n\n```ruby\nrequire 'regexgen'\n\nRegexgen.generate(['foobar', 'foobaz', 'foozap', 'fooza']) #=\u003e /foo(?:zap?|ba[rz])/\n```\n\n## CLI\n\n`regexgen` also has a simple CLI to generate regexes using inputs from the\ncommand line.\n\n```sh\n$ regexgen\nusage: regexgen [-mix] strings...\n    -m                               Multiline flag\n    -i                               Case-insensitive flag\n    -x                               Extended flag\n```\n\n## Unicode handling\n\nUnlike the JavaScript version, this package does not do any special Unicode\nhandling because Ruby does it all for you. You are recommended to use a Unicode\nencoding for your strings.\n\n## How does it work?\n\nJust like the JavaScript version:\n\n1. Generate a [Trie](https://en.wikipedia.org/wiki/Trie) containing all of the\n   input strings. This is a tree structure where each edge represents a single\n   character. This removes redundancies at the start of the strings, but common\n   branches further down are not merged.\n\n2. A trie can be seen as a tree-shaped deterministic finite automaton (DFA), so\n   DFA algorithms can be applied. In this case, we apply [Hopcroft's DFA\n   minimization\n   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\n   using [Brzozowski's algebraic\n   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\n   can be solved for a resulting regex. Along the way, some additional\n   optimizations are made, such as hoisting common substrings out of an\n   alternation, and using character class ranges. This produces an an [Abstract\n   Syntax Tree](https://en.wikipedia.org/wiki/Abstract_syntax_tree) (AST) for\n   the regex, which is then converted to a string and compiled to a Ruby\n   `Regexp` object.\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run\n`rake test` to run the tests. You can also run `bin/console` for an interactive\nprompt that will allow you to experiment.\n\nTo install this gem onto your local machine, run `bundle exec rake install`. To\nrelease a new version, update the version number in `version.rb`, and then run\n`bundle exec rake release`, which will create a git tag for the version, push\ngit commits and tags, and push the `.gem` file to\n[rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at\nhttps://github.com/amake/regexgen-ruby.\n\n\n## License\n\nThe gem is available as open source under the terms of the [MIT\nLicense](https://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famake%2Fregexgen-ruby","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Famake%2Fregexgen-ruby","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famake%2Fregexgen-ruby/lists"}