{"id":17203164,"url":"https://github.com/ltrzesniewski/pcre-net","last_synced_at":"2025-04-05T02:10:28.247Z","repository":{"id":21807615,"uuid":"25130251","full_name":"ltrzesniewski/pcre-net","owner":"ltrzesniewski","description":"PCRE.NET - Perl Compatible Regular Expressions for .NET","archived":false,"fork":false,"pushed_at":"2024-04-20T14:31:03.000Z","size":11754,"stargazers_count":142,"open_issues_count":1,"forks_count":13,"subscribers_count":10,"default_branch":"master","last_synced_at":"2024-04-26T12:48:03.380Z","etag":null,"topics":["c-sharp","extract","pcre","regex","regular-expression"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"zjucsc302/pedestrian_retrieval","license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ltrzesniewski.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2014-10-12T19:56:00.000Z","updated_at":"2024-06-13T01:49:06.897Z","dependencies_parsed_at":"2023-11-15T23:28:08.412Z","dependency_job_id":"3301495a-d0f1-4ef3-a86b-570db1fee637","html_url":"https://github.com/ltrzesniewski/pcre-net","commit_stats":{"total_commits":466,"total_committers":3,"mean_commits":"155.33333333333334","dds":"0.0042918454935622075","last_synced_commit":"eabd0bce7263d0bf127411ee7645cc8371eca13b"},"previous_names":[],"tags_count":35,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ltrzesniewski%2Fpcre-net","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ltrzesniewski%2Fpcre-net/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ltrzesniewski%2Fpcre-net/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ltrzesniewski%2Fpcre-net/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ltrzesniewski","download_url":"https://codeload.github.com/ltrzesniewski/pcre-net/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247276189,"owners_count":20912288,"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":["c-sharp","extract","pcre","regex","regular-expression"],"created_at":"2024-10-15T02:17:05.426Z","updated_at":"2025-04-05T02:10:28.233Z","avatar_url":"https://github.com/ltrzesniewski.png","language":"C#","funding_links":[],"categories":["C\\#"],"sub_categories":[],"readme":"# PCRE.NET                    \u003cpicture\u003e\u003csource media=\"(prefers-color-scheme: dark)\" srcset=\"icon-dark.png\"\u003e\u003cimg src=\"icon.png\" align=\"right\" alt=\"Logo\"\u003e\u003c/picture\u003e\n\n**Perl Compatible Regular Expressions for .NET**\n\n[![Build](https://github.com/ltrzesniewski/pcre-net/workflows/Build/badge.svg)](https://github.com/ltrzesniewski/pcre-net/actions?query=workflow%3ABuild)\n[![NuGet Package](https://img.shields.io/nuget/v/PCRE.NET.svg?logo=NuGet)](https://www.nuget.org/packages/PCRE.NET)\n[![GitHub release](https://img.shields.io/github/release/ltrzesniewski/pcre-net.svg?logo=GitHub)](https://github.com/ltrzesniewski/pcre-net/releases)\n[![PCRE2](https://img.shields.io/badge/pcre2-v10.45-blue.svg)](https://github.com/PCRE2Project/pcre2)\n[![License](https://img.shields.io/badge/license-BSD-blue.svg)](https://github.com/ltrzesniewski/pcre-net/blob/master/LICENCE)\n\u003cbr clear=\"right\" /\u003e\n\nPCRE.NET is a .NET wrapper for the [PCRE2 library](https://github.com/PCRE2Project/pcre2).\n\nThe following systems are supported:\n\n - Windows x64\n - Windows x86\n - Linux x64\n - Linux arm64\n - macOS arm64\n - macOS x64\n\n## API Types\n\n### The classic API\n\nThis is a friendly API that is very similar to .NET's `System.Text.RegularExpressions`. It works on `string` objects, and supports the following operations:\n\n- NFA matching and substring extraction:\n  - `Matches`\n  - `Match`\n  - `IsMatch`\n- Matched string replacement:\n  - Using `Replace`, the PCRE.NET API:\n    - Callbacks: `Func\u003cPcreMatch, string\u003e`\n    - Replacement strings with placeholders: ``$n ${name} $\u0026 $_ $` $' $+``\n  - Using `Substitute`, the PCRE2 API:\n      - Replacement strings with placeholders: ``$n ${n} $\u0026 $_ $` $' $$ $*MARK ${*MARK}``\n      - Callouts for matches and substitutions\n- String splitting on matches: `Split`\n\n### The Span API\n\n`PcreRegex` objects provide overloads which take a `ReadOnlySpan\u003cchar\u003e` parameter for the following methods:\n\n- `Matches`\n- `Match`\n- `IsMatch`\n- `Substitute`\n\nThese methods return a `ref struct` type when possible, but are otherwise similar to the classic API.\n\n### The zero-allocation API\n\nThis is the fastest matching API the library provides.\n\nCall the `CreateMatchBuffer` method on a `PcreRegex` instance to create the necessary data structures up-front, then use the returned _match buffer_ for subsequent match operations. Performing a match through this buffer will not allocate further memory, reducing GC pressure and optimizing the process.\n\nThe downside of this approach is that the returned match buffer is _not_ thread-safe and _not_ reentrant: you _cannot_ perform a match operation with a buffer which is already being used - match operations need to be sequential.\n\nIt is also counter-productive to allocate a match buffer to perform a single match operation. Use this API if you need to match a pattern against many subject strings.\n\n`PcreMatchBuffer` objects are disposable (and finalizable in case they're not disposed). They provide an API for matching against `ReadOnlySpan\u003cchar\u003e` subjects.\n\nIf you're looking for maximum speed, consider using the following options:\n\n- `PcreOptions.Compiled` at compile time to enable the JIT compiler, which will improve matching speed.\n- `PcreMatchOptions.NoUtfCheck` at match time to skip the Unicode validity check: by default PCRE2 scans the entire input string to make sure it's valid Unicode.\n- `PcreOptions.MatchInvalidUtf` at compile time if you plan to use `PcreMatchOptions.NoUtfCheck` and your subject strings may contain invalid Unicode sequences.\n\n### The DFA matching API\n\nThis API provides regex matching in O(_subject length_) time. It is accessible through the `Dfa` property on a `PcreRegex` instance:\n\n- `Dfa.Matches`\n- `Dfa.Match`\n\nYou can read more about its features in [the PCRE2 documentation](https://pcre2project.github.io/pcre2/doc/html/pcre2matching.html), where it's described as the _alternative matching algorithm_.\n\n## Library highlights\n\n- Support for compiled patterns (x86/x64 JIT)\n- Support for partial matching (when the subject is too short to match the pattern)\n- Callout support (numbered and string-based)\n- Mark retrieval support\n- Conversion from POSIX BRE, POSIX ERE and glob patterns (`PcreConvert` class)\n\n## Example usage\n\n- Extract all words except those within parentheses:\n\n```C#\nvar matches = PcreRegex.Matches(\"(foo) bar (baz) 42\", @\"\\(\\w+\\)(*SKIP)(*FAIL)|\\w+\")\n                       .Select(m =\u003e m.Value)\n                       .ToList();\n// result: \"bar\", \"42\"\n```\n\n- Enclose a series of punctuation characters within angle brackets using `Replace` (the PCRE.NET API):\n\n```C#\nvar result = PcreRegex.Replace(\"hello, world!!!\", @\"\\p{P}+\", \"\u003c$\u0026\u003e\");\n// result: \"hello\u003c,\u003e world\u003c!!!\u003e\"\n```\n\n- Enclose a series of punctuation characters within angle brackets using `Substitute` (the PCRE2 API):\n\n```C#\nvar result = PcreRegex.Substitute(\"hello, world!!!\", @\"\\p{P}+\", \"\u003c$0\u003e\", PcreOptions.None, PcreSubstituteOptions.SubstituteGlobal);\nAssert.That(result, Is.EqualTo(\"hello\u003c,\u003e world\u003c!!!\u003e\"));\n```\n\n- Partial matching:\n\n```C#\nvar regex = new PcreRegex(@\"(?\u003c=abc)123\");\nvar match = regex.Match(\"xyzabc12\", PcreMatchOptions.PartialSoft);\n// result: match.IsPartialMatch == true\n```\n\n- Validate a JSON string:\n\n```C#\nconst string jsonPattern = \"\"\"\n    (?(DEFINE)\n        # An object is an unordered set of name/value pairs.\n        (?\u003cobject\u003e \\{\n            (?: (?\u0026keyvalue) (?: , (?\u0026keyvalue) )* )?\n        (?\u0026ws) \\} )\n        (?\u003ckeyvalue\u003e\n            (?\u0026ws) (?\u0026string) (?\u0026ws) : (?\u0026value)\n        )\n\n        # An array is an ordered collection of values.\n        (?\u003carray\u003e \\[\n            (?: (?\u0026value) (?: , (?\u0026value) )* )?\n        (?\u0026ws) \\] )\n\n        # A value can be a string in double quotes, or a number,\n        # or true or false or null, or an object or an array.\n        (?\u003cvalue\u003e (?\u0026ws)\n            (?: (?\u0026string) | (?\u0026number) | (?\u0026object) | (?\u0026array) | true | false | null )\n        )\n\n        # A string is a sequence of zero or more Unicode characters,\n        # wrapped in double quotes, using backslash escapes.\n        (?\u003cstring\u003e\n            \" (?: [^\"\\\\\\p{Cc}]++ | \\\\u[0-9A-Fa-f]{4} | \\\\ [\"\\\\/bfnrt] )* \"\n            # \\p{Cc} matches control characters\n        )\n\n        # A number is very much like a C or Java number, except that the octal\n        # and hexadecimal formats are not used.\n        (?\u003cnumber\u003e\n            -? (?: 0 | [1-9][0-9]* ) (?: \\. [0-9]+ )? (?: [Ee] [-+]? [0-9]+ )?\n        )\n\n        # Whitespace\n        (?\u003cws\u003e \\s*+ )\n    )\n\n    \\A (?\u0026ws) (?\u0026object) (?\u0026ws) \\z\n    \"\"\";\n\nvar regex = new PcreRegex(jsonPattern, PcreOptions.IgnorePatternWhitespace);\n\nconst string subject = \"\"\"\n    {\n        \"hello\": \"world\",\n        \"numbers\": [4, 8, 15, 16, 23, 42],\n        \"foo\": null,\n        \"bar\": -2.42e+17,\n        \"baz\": true\n    }\n    \"\"\";\n\nvar isValidJson = regex.IsMatch(subject);\n// result: true\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fltrzesniewski%2Fpcre-net","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fltrzesniewski%2Fpcre-net","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fltrzesniewski%2Fpcre-net/lists"}