{"id":16793698,"url":"https://github.com/grandmoff100/regexfactory","last_synced_at":"2025-03-22T01:30:53.639Z","repository":{"id":43224355,"uuid":"420801618","full_name":"GrandMoff100/RegexFactory","owner":"GrandMoff100","description":"Dynamically construct regex patterns with native python representations","archived":false,"fork":false,"pushed_at":"2024-05-29T01:50:26.000Z","size":158,"stargazers_count":7,"open_issues_count":4,"forks_count":4,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-18T06:51:30.400Z","etag":null,"topics":["library","python","regex","regex-generator","regex-pattern","regular-expression","sphinx-documentation"],"latest_commit_sha":null,"homepage":"https://regexfactory.readthedocs.io","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/GrandMoff100.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":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-10-24T21:36:03.000Z","updated_at":"2024-12-30T22:26:26.000Z","dependencies_parsed_at":"2024-04-16T03:27:42.857Z","dependency_job_id":"56bc96f0-d35a-4301-a857-74528b929f4b","html_url":"https://github.com/GrandMoff100/RegexFactory","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GrandMoff100%2FRegexFactory","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GrandMoff100%2FRegexFactory/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GrandMoff100%2FRegexFactory/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GrandMoff100%2FRegexFactory/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/GrandMoff100","download_url":"https://codeload.github.com/GrandMoff100/RegexFactory/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244893361,"owners_count":20527581,"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":["library","python","regex","regex-generator","regex-pattern","regular-expression","sphinx-documentation"],"created_at":"2024-10-13T08:50:01.383Z","updated_at":"2025-03-22T01:30:53.321Z","avatar_url":"https://github.com/GrandMoff100.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# RegexFactory\n\nDynamically construct python regex patterns.\n\n## Examples\n\n### Matching Initials\n\nSay you want a regex pattern to match the initials of someones name.\n\n```python\nimport re\nfrom regexfactory import Amount, Range\n\n\npattern = Amount(Range(\"A\", \"Z\"), 2, 3)\n\nmatches = pattern.findall(\n    \"My initials are BDP. Valorie's are VO\"\n)\n\nprint(matches)\n```\n\n```bash\n['BDP', 'VO']\n```\n\n### Matching Hex Strings\n\nOr how matching both uppercase and lowercase hex strings in a sentence.\n\n```python\nimport re\nfrom regexfactory import *\n\npattern = Optional(\"#\") + Or(\n    Amount(\n        Set(\n            Range(\"0\", \"9\"),\n            Range(\"a\", \"f\")\n        ),\n        6\n    ),\n    Amount(\n        Set(\n            Range(\"0\", \"9\"),\n            Range(\"A\", \"F\")\n        ),\n        6\n    ),\n\n)\n\nsentence = \"\"\"\nMy favorite color is #000000. I also like 5fb8a0. My second favorite color is #FF21FF.\n\"\"\"\n\nmatches = pattern.findall(sentence)\nprint(matches)\n```\n\n```bash\n['#000000', '5fb8a0', '#FF21FF']\n```\n\n### Matching URLs\n\nOr what if you want to match urls in html content?\n\n```python\nfrom regexfactory import *\n\n\nprotocol = Amount(Range(\"a\", \"z\"), 1, or_more=True)\nhost = Amount(Set(WORD, DIGIT, '.'), 1, or_more=True)\nport = Optional(IfBehind(\":\") + Multi(DIGIT))\npath = Multi(\n    RegexPattern('/') + Multi(\n        NotSet('/', '#', '?', '\u0026', WHITESPACE),\n        match_zero=True\n    ),\n    match_zero=True\n)\npatt = protocol + RegexPattern(\"://\") + host + port + path\n\n\n\nsentence = \"This is a cool url, https://github.com/GrandMoff100/RegexFactory/ \"\nprint(patt)\n\nprint(patt.search(sentence))\n```\n\n```bash\n[a-z]{1,}://[\\w\\d.]{1,}(?:\\d{1,})?(/([^/#?\u0026\\s]{0,})){0,}\n\u003cre.Match object; span=(15, 51), match='https://github.com/GrandMoff100/RegexFactory/'\u003e\n```\n\n## The Pitch\n\nThis library is really good at allowing you to intuitively understand how to construct a regex expression.\nIt helps you identify what exactly your regular expression is, and can help you debug it.\nThis is library is also very helpful for generating regex expressions on the fly if you find uses for it.\nYou can also extend this library by subclassing `RegexPattern` and add your own support for different regex flavors.\nLike generating regex expresison with Perl5 extensions.\n\nThere you have it. This library is intuitive, extensible, modular, and dynamic.\nWhy not use it?\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgrandmoff100%2Fregexfactory","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgrandmoff100%2Fregexfactory","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgrandmoff100%2Fregexfactory/lists"}