{"id":13413981,"url":"https://github.com/hedhyw/rex","last_synced_at":"2025-04-04T11:15:36.323Z","repository":{"id":37015036,"uuid":"503052920","full_name":"hedhyw/rex","owner":"hedhyw","description":"Flexible regular expressions constructor for Golang.","archived":false,"fork":false,"pushed_at":"2025-03-26T02:43:29.000Z","size":691,"stargazers_count":202,"open_issues_count":0,"forks_count":5,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-28T10:09:41.052Z","etag":null,"topics":["builder-pattern","constructor","dsl","dsl-syntax","go","golang","regexp","regexp-builder","regular-expression","regular-expressions"],"latest_commit_sha":null,"homepage":"","language":"Go","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/hedhyw.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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}},"created_at":"2022-06-13T17:30:44.000Z","updated_at":"2025-03-26T02:43:32.000Z","dependencies_parsed_at":"2024-06-18T21:31:14.809Z","dependency_job_id":"a746cf6a-7866-4f5b-b81a-a034fc19384b","html_url":"https://github.com/hedhyw/rex","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hedhyw%2Frex","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hedhyw%2Frex/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hedhyw%2Frex/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hedhyw%2Frex/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hedhyw","download_url":"https://codeload.github.com/hedhyw/rex/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247166169,"owners_count":20894654,"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":["builder-pattern","constructor","dsl","dsl-syntax","go","golang","regexp","regexp-builder","regular-expression","regular-expressions"],"created_at":"2024-07-30T20:01:54.339Z","updated_at":"2025-04-04T11:15:36.302Z","avatar_url":"https://github.com/hedhyw.png","language":"Go","readme":"# Rex\n\n![Version](https://img.shields.io/github/v/tag/hedhyw/rex)\n[![Go Report Card](https://goreportcard.com/badge/github.com/hedhyw/rex)](https://goreportcard.com/report/github.com/hedhyw/rex)\n[![Coverage Status](https://coveralls.io/repos/github/hedhyw/rex/badge.svg?branch=main)](https://coveralls.io/github/hedhyw/rex?branch=main)\n[![PkgGoDev](https://pkg.go.dev/badge/github.com/hedhyw/rex)](https://pkg.go.dev/github.com/hedhyw/rex?tab=doc)\n\n![rex-gopher](_docs/gopher.png)\n\n**This is a regular expressions builder for gophers!**\n\n- **[Why?](#why)**\n- **[FAQ](#faq)**\n- **[Documentation](_docs/library.md)**\n- **[Examples](pkg/rex/examples_test.go)**\n- **[License](#license)**\n\n## Why?\n\nIt makes readability better and helps to construct regular expressions using human-friendly constructions. Also, it allows commenting and reusing blocks, which improves the quality of code. It provides a convenient way to use parameterized patterns. It is easy to implement custom patterns or use a combination of others.\n\nIt is just a builder, so it returns standart [`*regexp.Regexp`](https://pkg.go.dev/regexp#Regexp).\n\nThe library supports [groups](_docs/library.md#groups), [composits](_docs/library.md#groups), [classes](_docs/library.md#character-classes), [flags](_docs/library.md#flags), [repetitions](_docs/library.md#repetitions) and if you want you can even use `raw regular expressions` in any place. Also it contains a set of [predefined helpers](_docs/library.md#helper) with patterns for number ranges, phones, emails, etc...\n\nLet's see an example of validating or matching `someid[#]` using a verbose pattern:\n```golang\nre := rex.New(\n    rex.Chars.Begin(), // `^`\n    // ID should begin with lowercased character.\n    rex.Chars.Lower().Repeat().OneOrMore(), // `[a-z]+`\n    // ID should contain number inside brackets [#].\n    rex.Group.NonCaptured( // (?:)\n        rex.Chars.Single('['),                   // `[`\n        rex.Chars.Digits().Repeat().OneOrMore(), // `[0-9]+`\n        rex.Chars.Single(']'),                   // `]`\n    ),\n    rex.Chars.End(), // `$`\n).MustCompile()\n```\n\nYes, it requires more code, but it has its advantages.\n\u003e More, but simpler code, fewer bugs.\n\nYou can still use original regular expressions as is in any place. Example of\nmatching numbers between `-111.99` and `1111.99` using a combination of\npatterns and raw regular expression:\n\n```golang\nre := rex.New(\n    rex.Common.Raw(`^`),\n    rex.Helper.NumberRange(-111, 1111),\n    rex.Common.RawVerbose(`\n        # RawVerbose is a synonym to Raw,\n        # but ignores comments, spaces and new lines.\n        \\.        # Decimal delimter.  \n        [0-9]{2}  # Only two digits.\n        $         # The end.\n    `),\n).MustCompile()\n\n// Produces:\n// ^((?:\\x2D(?:0|(?:[1-9])|(?:[1-9][0-9])|(?:10[0-9])|(?:11[0-1])))|(?:0|(?:[1-9])|(?:[1-9][0-9])|(?:[1-9][0-9][0-9])|(?:10[0-9][0-9])|(?:110[0-9])|(?:111[0-1])))\\.[0-9]{2}$\n```\n\n\u003e The style you prefer is up to you.\n\n## Meme\n\n\u003cimg alt=\"Drake Hotline Bling meme\" width=350px src=\"_docs/meme.png\" /\u003e\n\n## FAQ\n\n1. **It is too verbose. Too much code.**\n\n    More, but simpler code, fewer bugs.\n    Anyway, you can still use the raw regular expressions syntax in combination with helpers.\n    ```golang\n    rex.New(\n        rex.Chars.Begin(),\n        rex.Group.Define(\n            // `Raw` can be placed anywhere in blocks.\n            rex.Common.Raw(`[a-z]+\\d+[A-Z]*`),\n        ),\n        rex.Chars.End(),\n    )\n    ```\n    Or just raw regular expression with comments:\n    ```golang\n    rex.Common.RawVerbose(`\n        ^                # Start of the line.\n        [a-zA-Z0-9]+     # Local part.\n        @                # delimeter.\n        [a-zA-Z0-9\\.]+   # Domain part.\n        $                # End of the line.\n    `)\n    ```\n\n2. **Should I know regular expressions?**\n\n   It is better to know them in order to use this library most effectively.\n   But in any case, it is not strictly necessary.\n\n3. **Is it language-dependent? Is it transferable to other languages?**\n\n   We can use this library only in Go. If you want to use any parts\n   in other places, then just call `rex.New(...).String()` and copy-paste\n   generated regular expression.\n\n4. **What about my favourite `DSL`?**\n\n   Every IDE has convenient auto-completion for languages. So all helpers\n   of this library are easy to use out of the box. Also, it is easier\n   to create custom parameterized helpers.\n\n5. **Is it stable?**\n\n   Yes, starting with version v1.0.0.\n\n6. **I have another question. I found an issue. I have a feature request. I want to contribute.**\n\n   Please, [create an issue](https://github.com/hedhyw/rex/issues/new?labels=question\u0026title=I+have+a+question).\n\n## License\n\n- The library is under [MIT Lecense](LICENSE)\n- [The gopher](_docs/gopher.png) is under [Creative Commons Attribution 3.0](https://creativecommons.org/licenses/by/3.0/) license. It was originally created by [Renée French](https://en.wikipedia.org/wiki/Ren%C3%A9e_French) and redrawed by me.\n- [The meme](_docs/meme.png) contains two frame fragments from [the video](https://www.youtube.com/watch?v=uxpDa-c-4Mc).\n","funding_links":[],"categories":["Go","Text Processing","Template Engines","文本处理","Bot Building"],"sub_categories":["Regular Expressions","正则表达式"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhedhyw%2Frex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhedhyw%2Frex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhedhyw%2Frex/lists"}