{"id":15092573,"url":"https://github.com/zhorton34/irregular-expression","last_synced_at":"2026-01-04T15:46:40.087Z","repository":{"id":256925312,"uuid":"856799089","full_name":"zhorton34/irregular-expression","owner":"zhorton34","description":"Just your everyday irregular expression fluently implemented","archived":false,"fork":false,"pushed_at":"2024-09-13T10:03:23.000Z","size":13,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-27T11:16:34.074Z","etag":null,"topics":["deno","javascript","js","regex","regexp","ts","typescript"],"latest_commit_sha":null,"homepage":"https://find.how","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/zhorton34.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":"2024-09-13T08:20:27.000Z","updated_at":"2024-09-13T10:07:04.000Z","dependencies_parsed_at":"2024-09-13T23:45:13.882Z","dependency_job_id":"7b4a007b-894c-426b-8991-1384f37e1e89","html_url":"https://github.com/zhorton34/irregular-expression","commit_stats":null,"previous_names":["zhorton34/irregular-expression"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhorton34%2Firregular-expression","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhorton34%2Firregular-expression/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhorton34%2Firregular-expression/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhorton34%2Firregular-expression/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zhorton34","download_url":"https://codeload.github.com/zhorton34/irregular-expression/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244952554,"owners_count":20537467,"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":["deno","javascript","js","regex","regexp","ts","typescript"],"created_at":"2024-09-25T11:01:24.543Z","updated_at":"2026-01-04T15:46:40.060Z","avatar_url":"https://github.com/zhorton34.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# IrregularExpression 📐\n\nA fluent, human-readable wrapper for building and using regular expressions in TypeScript/Deno! Simplify regex creation with an intuitive, chainable API, making complex patterns more accessible and less error-prone.\n\n## 🚀 Quick Start\n\n- 🔧 **Install:** Easily add `IrregularExpression` to your Deno project.\n- 📚 **Documentation:** Comprehensive API details for full control over regex.\n- 🧪 **Examples:** Practical, real-world examples to get you started immediately.\n- 💬 **Contribute:** Join the community to improve and extend the module.\n\n## 🔧 Installation\n\nTo use `IrregularExpression` in your Deno project, import it directly from the URL:\n\n```typescript\nimport { IrregularExpression } from \"@findhow/irregular-expression\";\n```\n\n## 📚 API Overview\n\n### `IrregularExpression.match()`\nInitialize a new regex builder.\n\n```typescript\nconst pattern = IrregularExpression.match()\n  .startOfLine()\n  .exactly(3).digit()\n  .then('-')\n  .exactly(3).digit()\n  .then('-')\n  .exactly(4).digit()\n  .endOfLine()\n  .build();\n\n\"Some string\".test(pattern)\n```\n\n### Features\n- **Flags**: `ignoreCase()`, `multiline()`, `dotAll()`, `unicode()`\n- **Quantifiers**: `exactly(n)`, `atLeast(n)`, `between(n, m)`, `zeroOrMore()`, `oneOrMore()`, `zeroOrOne()`\n- **Character Classes**: `digit()`, `nonDigit()`, `wordCharacter()`, `nonWordCharacter()`, `whitespace()`, `nonWhitespace()`, `anyCharacterExcept(chars)`\n- **Position Matching**: `startOfLine()`, `endOfLine()`, `wordBoundary()`\n- **Groups and Lookarounds**: `capture()`, `namedCapture()`, `nonCapturingGroup()`, `positiveLookahead()`, `negativeLookahead()`, `positiveLookbehind()`, `negativeLookbehind()`\n- **Others**: `literal()`, `anySingleCharacter()`, `range()`, `notInRange()`, `anyOf()`, `noneOf()`, `or()`, `combine()`, `backreference()`, `namedBackreference()`\n\n### Methods\n- **`build()`** - Builds and returns the RegExp object.\n- **`test(input)`** - Tests if the regex matches the input string.\n- **`execute(input)`** - Executes the regex on the input string and returns the match results.\n- **`replace(input, replacement)`** - Replaces matches in the input string with the provided replacement.\n\n## 🧪 Usage Examples\n\n### Example 1: Simple Phone Number Validator\n\n```typescript\nconst regex = IrregularExpression.match()\n  .startOfLine()\n  .exactly(3).digit()\n  .then('-')\n  .exactly(3).digit()\n  .then('-')\n  .exactly(4).digit()\n  .endOfLine()\n  .build();\n\nconsole.log(regex.toString()); // Outputs: /^\\d{3}-\\d{3}-\\d{4}$/\nconsole.log(regex.test(\"123-456-7890\")); // true\nconsole.log(regex.test(\"12-34-5678\")); // false\n```\n\n### Example 2: Extract Data from Serialized JSON\n\nUse `IrregularExpression` to find and extract specific values from serialized JSON.\n\n```typescript\nconst jsonRegex = IrregularExpression.match()\n  .literal('\"name\"')\n  .whitespace().zeroOrMore()\n  .literal(':')\n  .whitespace().zeroOrMore()\n  .literal('\"')\n  .\n```\n\n### Example 3: Scrape Specific Log Information from a Large Text File\n\nExtract all error messages from a log file where each error message is prefixed by `[ERROR]`.\n\n```typescript\nconst logRegex = IrregularExpression.match()\n  .literal(\"[ERROR]\")\n  .whitespace()\n  .capture(group =\u003e group\n    .anySingleCharacter()\n    .zeroOrMore()\n  )\n  .build();\n\nconst logContent = `\n[INFO] Application started\n[ERROR] Failed to connect to database\n[WARNING] Low disk space\n[ERROR] User authentication failed\n`;\n\nconst errors = logRegex.execute(logContent);\nconsole.log(errors.map(error =\u003e error[1])); \n// Outputs: [\"Failed to connect to database\", \"User authentication failed\"]\n```\n\n### Example 4: Work with Property Addresses and Names\n\nExtract property addresses and full names (first, middle, last) from inconsistent data formats.\n\n```typescript\nconst addressRegex = IrregularExpression.match()\n  .capture(group =\u003e group\n    .digit()\n    .oneOrMore()\n  )\n  .whitespace()\n  .capture(group =\u003e group\n    .anyOf('a-zA-Z')\n    .oneOrMore()\n  )\n  .whitespace()\n  .capture(group =\u003e group\n    .anyOf('a-zA-Z')\n    .oneOrMore()\n  )\n  .build();\n\nconst addressString = \"123 Main St, Apt 4B\";\nconst addressParts = addressRegex.execute(addressString);\nconsole.log(addressParts.map(part =\u003e part[0])); \n// Outputs: [\"123\", \"Main\", \"St\"]\n\nconst nameRegex = IrregularExpression.match()\n  .capture(group =\u003e group\n    .wordCharacter()\n    .oneOrMore()\n  )\n  .whitespace()\n  .capture(group =\u003e group\n    .wordCharacter()\n    .oneOrMore()\n    .zeroOrOne()\n  )\n  .whitespace()\n  .capture(group =\u003e group\n    .wordCharacter()\n    .oneOrMore()\n  )\n  .build();\n\nconst nameString = \"John Michael Doe\";\nconst nameParts = nameRegex.execute(nameString);\nconsole.log(nameParts.map(part =\u003e part[0])); \n// Outputs: [\"John\", \"Michael\", \"Doe\"]\n```\n\n### Example 5: Replace Words in a Sentence\n\n```typescript\nconst regex = IrregularExpression.match()\n  .literal(\"cat\");\n\nconst input = \"The cat sat on the mat.\";\nconst result = regex.replace(input, \"dog\");\nconsole.log(result); // \"The dog sat on the mat.\"\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzhorton34%2Firregular-expression","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzhorton34%2Firregular-expression","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzhorton34%2Firregular-expression/lists"}