{"id":13598970,"url":"https://github.com/StartAutomating/Irregular","last_synced_at":"2025-04-10T10:30:45.749Z","repository":{"id":40785173,"uuid":"208742462","full_name":"StartAutomating/Irregular","owner":"StartAutomating","description":"Regular Expressions made Strangely Simple","archived":false,"fork":false,"pushed_at":"2024-09-22T22:17:11.000Z","size":1110,"stargazers_count":106,"open_issues_count":44,"forks_count":8,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-08T17:51:14.693Z","etag":null,"topics":["powershell","powershell-modules","regex","regexp","regular-expression"],"latest_commit_sha":null,"homepage":"https://irregular.start-automating.com/","language":"PowerShell","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/StartAutomating.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"github":["StartAutomating"]}},"created_at":"2019-09-16T07:56:19.000Z","updated_at":"2025-04-02T13:35:02.000Z","dependencies_parsed_at":"2024-04-16T01:46:11.219Z","dependency_job_id":"2d066ca2-1f09-4110-8743-bc417007fd70","html_url":"https://github.com/StartAutomating/Irregular","commit_stats":null,"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StartAutomating%2FIrregular","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StartAutomating%2FIrregular/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StartAutomating%2FIrregular/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StartAutomating%2FIrregular/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/StartAutomating","download_url":"https://codeload.github.com/StartAutomating/Irregular/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248199136,"owners_count":21063641,"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":["powershell","powershell-modules","regex","regexp","regular-expression"],"created_at":"2024-08-01T17:00:58.602Z","updated_at":"2025-04-10T10:30:44.486Z","avatar_url":"https://github.com/StartAutomating.png","language":"PowerShell","readme":"\u003cdiv align='center'\u003e\n\u003cimg src='assets/Irregular.svg' /\u003e\n\u003ch2\u003eRegular Expressions made Strangely Simple\u003c/h2\u003e\n\u003ch3\u003eA PowerShell module that helps you understand, use, and build Regular Expressions.\u003c/h3\u003e\n\u003ch4\u003e\n\u003ca href='https://github.com/StartAutomating/Irregular/releases/tag/v0.7.9'\u003ev 0.7.9 \u003c/a\u003e\n\u003c/h4\u003e\n\u003ca href='https://www.powershellgallery.com/packages/Irregular/'\u003e\n\u003cimg src='https://img.shields.io/powershellgallery/dt/Irregular' /\u003e\n\u003c/a\u003e\n\u003cbr/\u003e\n\u003ca href='https://github.com/StartAutomating/Irregular/actions/workflows/IrregularTests.yml'\u003e\n\u003cimg src='https://github.com/StartAutomating/Irregular/actions/workflows/IrregularTests.yml/badge.svg' /\u003e\n\u003c/a\u003e\n\u003c/div\u003e\n\n\n\n\n#### Understanding Regular Expressions\n\nRegular Expressions are powerful but feared.\n\nThey are powerful because they can can be used to parse anything.\n\nThey are feared because their syntax is so strange it obscures basic understanding.\n\nOnce you understand some basics of that syntax, regular expressions become a lot less scary (although they still look strange)\n\n1. You can stack a RegEx!  (by placing them in capture groups () )\n2. You can extract from a RegEx!  ( by naming a capture group (?\\\u003cDigits\\\u003e\\d+)).\n3. A Regex can have comments! ( # Like this in .NET  ( or like (?#this comment) in ECMAScript ) ).\n4. You don't have to do it all in one expression! \n\nIrregular comes with 147 useful [named expressions](SavedPatterns.md), and lets you create more.\n\nTo see the expressions that ship with Irregular, run:\n\n~~~PowerShell\nGet-RegEx\n~~~\n\nYou can use them in all sorts of interesting ways in PowerShell with the capture name:\n\n~~~PowerShell\n?\u003cDigits\u003e                    # Returns the Named Regular Expression Digits\n'abc' | ?\u003cDigits\u003e            # Returns nothing, since nothing in abc matches the expression Digits\n'123abc456' | ?\u003cDigits\u003e      # Returns two matches, 123 and 456\n\"abc123\" | ?\u003cDigits\u003e -Until  # Returns the content until the next set of digits\n'1. one. 2. two.  3. three'| # Returns each number and the content after it\n    ?\u003cDigits\u003e -Split -IncludeMatch\n'123abc456def' |             # Returns only matches of odd Digits\n    ?\u003cDigits\u003e -Where { $_.Digits % 2 } \n~~~\n\nYou can use these expressions to build more complicated parsing in less code.\nFor instance, here's a Regular Expression that can match a simple calculator:\n\n    \n~~~PowerShell\nNew-RegEx -StartAnchor StringStart -Pattern @(\n    ?\u003cOptionalWhitespace\u003e\n    ?\u003cDigits\u003e\n    ?\u003cOptionalWhitespace\u003e\n    ?\u003cArithmeticOperator\u003e\n    ?\u003cOptionalWhitespace\u003e\n    ?\u003cDigits\u003e\n    ?\u003cOptionalWhitespace\u003e\n) -EndAnchor StringEnd\n~~~\n\n\nIrregular also contains a colorized PowerShell formatter for all Regular Expressions.\nThis provides syntax highlighting that can make complicated expressions easier to read.\n![RegexSyntaxHighlighting](assets/RegexSyntaxHighlighting.gif)\n\n\n#### Building Regular Expressions\n\nIrregular gives you a handy command to simplify writing regular expressions, New-RegEx.\n\nNew-RegEx helps you build regular expressions without constantly resorting to a manual.\n\n~~~PowerShell\nNew-RegEx -CharacterClass Digit -Repeat # This writes the Regex (\\d+)\n~~~\nYou can pipe regular expression written this way into New-RegEx to compound expressions\n    \n~~~PowerShell\n# This will produce a regular expression that matches a doubly-quoted string (allowing for escaped quotes)\nNew-RegEx -Pattern '\"' |\n        New-RegEx -CharacterClass Any -Repeat -Lazy -Before (\n            New-RegEx -Pattern '\"' -NotAfter '\\\\'\n        ) |\n        New-RegEx -Pattern '\"'\n~~~\n\nThe parameters for New-RegEx have help, so if you ever want to understand a little more about what makes a RegEx, you can use:\n\n~~~PowerShell\nGet-Help New-RegEx -Full\n~~~\n\n#### Using Regular Expressions\n\nPowerShell is already a very potent tool for using Regular Expressions.\n\nYou can use the -match, -split, and -replace operators to do basic operations with Regular Expressions.\n\nYou can use any saved expression with these operators by putting it in paranthesis, for instance:\n\n~~~PowerShell\n\"abc123\" -match (?\u003cDigits\u003e)\n~~~\n\nThis works because without any additional parameters, running a saved expression will return a saved expression.\n\nAdditionally, each named capture can do a number of other things with a match:\n\n* -Where will filter matches\n* -IsMatch will return a boolean if the pattern matches\n* -Measure will count the number of matches\n* -Remove will strip any matches\n* -Replace will replace matches with a replacement string\n* -ReplaceIf will replace matches if a condition is met\n* -Transform will return matches transformed by a replacement string\n* -Coerce will coerce returned strings into strongly typed data\n* -Split will split the string on the matches (-Count number of times)\n* -Until will return the string until the next match\n* -RightToLeft will perform operations from right to left\n\nTo see all of the things you can do with any Regular Expression, run:\n\n~~~PowerShell\nGet-Help Use-Regex -Full\n~~~\n\nMatches are also decorated with information about the input and position.  This allows you to pipe one match into another search:\n\n~~~PowerShell\n\"\nnumber: 1\nstring: 'hello'\n\" | \n    ?\u003cNewLine\u003e -Split |     \n    Foreach-Object {\n        $key, $value  = $_ | ?\u003cColon\u003e -Split -Count 1\n        if ($key) {\n            @{$key=$value}\n        }\n    }\n~~~\n\n\n","funding_links":["https://github.com/sponsors/StartAutomating"],"categories":["PowerShell"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FStartAutomating%2FIrregular","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FStartAutomating%2FIrregular","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FStartAutomating%2FIrregular/lists"}