{"id":16800578,"url":"https://github.com/ahkhanjani/regez","last_synced_at":"2026-01-27T07:34:45.179Z","repository":{"id":57352375,"uuid":"323154429","full_name":"ahkhanjani/RegEz","owner":"ahkhanjani","description":"RegEz is a RegEx generator for coding regular expressions in JavaScript.","archived":false,"fork":false,"pushed_at":"2022-08-08T03:26:57.000Z","size":159,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-09-14T12:32:01.147Z","etag":null,"topics":["javascript","regex","regex-generator","regexp","regular-expression","regular-expressions","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/ahkhanjani.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}},"created_at":"2020-12-20T20:01:46.000Z","updated_at":"2023-01-06T16:09:52.000Z","dependencies_parsed_at":"2022-09-19T10:30:48.698Z","dependency_job_id":null,"html_url":"https://github.com/ahkhanjani/RegEz","commit_stats":null,"previous_names":["blooak/regez"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ahkhanjani/RegEz","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahkhanjani%2FRegEz","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahkhanjani%2FRegEz/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahkhanjani%2FRegEz/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahkhanjani%2FRegEz/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ahkhanjani","download_url":"https://codeload.github.com/ahkhanjani/RegEz/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahkhanjani%2FRegEz/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28808040,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-27T07:14:39.408Z","status":"ssl_error","status_checked_at":"2026-01-27T07:14:39.098Z","response_time":168,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["javascript","regex","regex-generator","regexp","regular-expression","regular-expressions","typescript"],"created_at":"2024-10-13T09:34:02.799Z","updated_at":"2026-01-27T07:34:45.149Z","avatar_url":"https://github.com/ahkhanjani.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# RegEz \u0026middot; [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/blooak/regez/blob/master/LICENSE) [![npm version](https://img.shields.io/npm/v/regez.svg?style=flat)](https://www.npmjs.com/package/regez)\n\nRegEz is a RegEx generator for coding regular expressions in JavaScript.\n\n## Installation\n\nUsing Yarn:\n\n```bash\nyarn add regez\n```\n\nUsing NPM:\n\n```bash\nnpm i regez\n```\n\n## Introduction\n\nThe goal is to create simple small blocks of RegEx and putting them together to create more complex RegExs, in a way more readable and understandable way.\n\nWe write all the RegEx using English and JavaScript syntax. Of course understanding the RegEx language is essential; But we will not write anything but pure English and JavaScript.\n\n## Tutorial\n\nAs an example, we want to create a simple RegEx for email validation.\n\nConsider an email address like this: `NAME@DOMAIN.EXT`.\n\nOur rules for a valid email address are going to be:\n\n**Note:** For a real life project, you need to add more rules to this example.\n\n- **NAME**\n\n  - Can only contain letters, digits, underscores and dots.\n  - Has to be at least 5 and at most 32 characters.\n  - Cannot start or end with an underscore or a dot.\n\n- **DOMAIN**\n\n  - Can only contain letters.\n  - Has to be at least 3 and at most 12 characters.\n\n- **EXT**\n  - Can only contain letters.\n  - Has to be at least 2 and at most 8 characters.\n\nEach one of them is going to be a block of RegEx.\n\n### Blocks\n\nImport the `Block` module:\n\n```javascript\nimport { Block } from 'regez';\n```\n\nLet's create the blocks.\n\n#### NAME\n\nCreate the `NAME` block like this:\n\n```javascript\nconst NAME = new Block('single-char');\n```\n\n**Explanation:**\n\n- `Block` is a class module so we need to use the `new` keyword.\n- We have two types of blocks:\n\n  - `literal`: Matches the block literally. Same as `/.../`.\n  - `single-char`: Matches any of the characters of the block; Meaning that the order is not important. Same as `/[...]/`.\n\n  Since `NAME` can be anything, we will use a `single-char` block.\n\n**Rule 1:** Can only contain letters, digits, underscores and dots.\n\nTo add perfect groups of characters such as all letters, we will use a method called `all()`:\n\n```javascript\nconst NAME = new Block('single-char').all('letters', 'digits');\n\n// Result: /[a-zA-Z\\d]/\n```\n\nTo add underscore and dot, we use the `chars()` method:\n\n```javascript\nconst NAME = new Block('single-char').all('letters', 'digits').chars('_.');\n\n// Result: /[a-zA-Z\\d_\\.]/\n```\n\n**Note:** Using a dot without escaping means matching all characters. RegEz adds a backslash to all special characters, meaning that you want to match that character literally; Not the special meaning of it.\n\n**Rule 2:** Has to be at least 5 and at most 32 characters.\n\nThe current result matches only one character of those that we added. To add the length limit, we will use the `repeats()` method:\n\n```javascript\nconst NAME = new Block('single-char')\n  .all('letters', 'digits')\n  .chars('_.')\n  .repeats({ atLeast: 5, atMost: 32 });\n\n// Result: /[a-zA-Z\\d_\\.]{5,32}/\n```\n\n**Note:** Method `repeats()` only works for `single-char` blocks. It has no effect on a `literal` block.\n\nMethod `repeats()` includes the following options:\n\n- `times`: Gets one of the following values:\n  - `zero-or-one`: Matches one character or nothing. Same as `/[...]?/`.\n  - `zero-or-more`: Matches unlimited length of characters. Same as `/[...]*/`.\n  - `one-or-more`: Matches at least one character. Same as `/[...]+/`.\n- `exactly`: The exact number of repeats. For example `/[...]{3}/`.\n- `atLeast`: The minimum number of repeats. For example `/[...]{3,}/`.\n- `atMost`: The maximum number of repeats. For example `/[...]{,3}/`.\n\n**Note:** You can use `atLeast` and `atMost` together. If you use the other options along with each other, the more important one will be considered:\n\n_Options by importance: times \u003e exactly \u003e atLeast = atMost._\n\n**Rule 3:** Cannot start or end with an underscore or a dot.\n\nTo apply this rule we have to create another block like this:\n\n```javascript\nconst _NAME = new Block('single-char').chars('_.');\n\n// Result: /[_\\.]/\n```\n\n**Explanation:** To show that this is a rule for the beginning of `NAME`, I use an underscore before it. You can name it whatever you want.\n\nTo say that we **don't want** these characters, we use the the `except()` method:\n\n```javascript\nconst _NAME = new Block('single-char').except().chars('_.');\n\n// Result: /[^_\\.]/\n```\n\nTo make it more visible for this example, I make a copy of `_NAME` as `NAME_` for the end of `NAME` but you don't have to, since they're exactly the same.\n\n#### DOMAIN and EXT\n\nLike what we did with `NAME`:\n\n```javascript\nconst DOMAIN = new Block('single-char')\n  .all('letters')\n  .repeats({ atLeast: 3, atMost: 12 });\n\n// Result: /[a-zA-Z]{3,12}/\n\nconst EXT = new Block('single-char')\n  .all('letters')\n  .repeats({ atLeast: 2, atMost: 8 });\n\n// Result: /[a-zA-Z]{2,8}/\n```\n\nAll blocks have been created. Now we put them together.\n\n### RegEz:\n\nThe `RegEz` module will do this for us.\n\n```javascript\nimport { RegEz } from 'regez';\n\nconst emailRegEx = RegEz();\n```\n\nImagine a structure of blocks like this: `((_NAME)(NAME)(NAME_))@(DOMAIN).(EXT)`.\n\nTo achieve this, we pass an \"in-inny!\" array of blocks as the first parameter:\n\n```javascript\nconst emailRegEx = RegEz([\n  [[_NAME], [NAME], [NAME_]],\n  '@',\n  [DOMAIN],\n  '.',\n  [EXT],\n]);\n\n// Result: /(([^\\d_\\.])([a-zA-Z\\d_\\.]{5,32})([^\\d_\\.]))@([a-zA-Z]{3,12})\\.([a-zA-Z]{2,8})/\n```\n\n**Explanation:**\n\n- As you can see, you can use both blocks and strings. Strings will match literally.\n- If you use special characters in strings, RegEz will add a backslash to them and disable their special behavior.\n- You can use nested arrays with any structure and depth you want; But too deep may cause stack overflow.\n\n#### Flags\n\nYou can pass an array of RegEx flags as the second parameter. For this example, we want our RegEx to be case-insensitive. So we use the _insensitive_ flag:\n\n```javascript\nconst emailRegEx = RegEz(\n  [[[_NAME], [NAME], [NAME_]], '@', [DOMAIN], '.', [EXT]],\n  ['insensitive']\n);\n\n// Result: /(([^_\\.])([a-zA-Z\\d_\\.]{5,32})([^_\\.]))@([a-zA-Z]{3,12})\\.([a-zA-Z]{2,8})/i\n```\n\nThis will add the `i` flag to the RegEx: `/.../i`.\n\nSee all RegEx flags [here](https://javascript.info/regexp-introduction#flags).\n\n#### Begin ^ and End $\n\nWe expect an email string without anything before and after it. For example we don't want a match for: \"hello kitkat1970@goomail.yum world!\".\n\nTo achieve this, we pass `startOfLine` and `endOfLine` as the third and the fourth parameters:\n\n```javascript\nconst emailRegEx = RegEz(\n  [[[_NAME], [NAME], [NAME_]], '@', [DOMAIN], '.', [EXT]],\n  ['insensitive'],\n  true,\n  true\n);\n```\n\nThis will add the `^` and the `$` to the RegEx: `/^...$/`. So the final result is:\n\n```regexp\n/^(([^_\\.])([a-zA-Z\\d_\\.]{5,32})([^_\\.]))@([a-zA-Z]{3,12})\\.([a-zA-Z]{2,8})$/i\n```\n\nNow the RegEx is complete. Module `RegEz` returns a RegExp object. So you can test a string like this:\n\n```javascript\nemailRegEx.test('kitkat1970@goomail.yum');\n\n// Result: true\n```\n\n## Configuration\n\nRegEz prevents usual RegExp errors that crash the app. Instead it logges **Sweet Errors** that provide a solution to fix the error. It also logges warnings if you're doing something wrong or there's a better way of doing things.\n\nTo disable Sweet Errors and warnings, you can create the `regez.config.json` file in the root directory of your project like this:\n\n```json\n{\n  \"fullErrors\": true,\n  \"noWarnings\": true\n}\n```\n\n## TypeScript\n\nAll type declarations come with the library in a `.d.ts` file.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fahkhanjani%2Fregez","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fahkhanjani%2Fregez","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fahkhanjani%2Fregez/lists"}