{"id":26271772,"url":"https://github.com/maipa01/pcre2cpp","last_synced_at":"2026-05-27T20:31:42.554Z","repository":{"id":282135988,"uuid":"947288154","full_name":"MAIPA01/pcre2cpp","owner":"MAIPA01","description":"A C++ wrapper around the PCRE2 library to provide a more user-friendly and object-oriented interface for using regular expressions, while retaining the performance and flexibility of the original library.","archived":false,"fork":false,"pushed_at":"2025-04-23T17:40:49.000Z","size":222,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-29T15:18:09.723Z","etag":null,"topics":["bsd-3-clause","cpp","cpp20","library","open-source","pcre2","pcre2-regex","pcre2-wrapper","regex","regular-expressions","wrapper"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MAIPA01.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,"zenodo":null}},"created_at":"2025-03-12T13:02:28.000Z","updated_at":"2025-04-23T17:40:53.000Z","dependencies_parsed_at":"2025-05-29T15:19:28.323Z","dependency_job_id":null,"html_url":"https://github.com/MAIPA01/pcre2cpp","commit_stats":null,"previous_names":["maipa01/pcre2cpp"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/MAIPA01/pcre2cpp","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MAIPA01%2Fpcre2cpp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MAIPA01%2Fpcre2cpp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MAIPA01%2Fpcre2cpp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MAIPA01%2Fpcre2cpp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MAIPA01","download_url":"https://codeload.github.com/MAIPA01/pcre2cpp/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MAIPA01%2Fpcre2cpp/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":272024993,"owners_count":24860528,"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","status":"online","status_checked_at":"2025-08-25T02:00:12.092Z","response_time":1107,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["bsd-3-clause","cpp","cpp20","library","open-source","pcre2","pcre2-regex","pcre2-wrapper","regex","regular-expressions","wrapper"],"created_at":"2025-03-14T07:14:40.027Z","updated_at":"2026-05-27T20:31:42.548Z","avatar_url":"https://github.com/MAIPA01.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pcre2cpp\n\n**pcre2cpp** is a C++ wrapper for the PCRE2 (Perl Compatible Regular Expressions) library written in C. It provides an\nobject-oriented interface for the original PCRE2 library, while maintaining the same functionality and\nbehavior. [DOCS](https://maipa01.github.io/pcre2cpp/html \"Documentation\")\n\n## Features\n\n- Object-oriented interface to PCRE2 10.47.\n- Compatible with C++17 and newer.\n- Easy to use regular expression matching with built-in result capturing.\n\n## Requirements\n\n- C++17 or newer.\n- CMAKE 3.30 or newer\n\n## Options\n\n### Compilation defines options\n\nYou can enable option using `#define option_name` or use cmake `set(option_name ON CACHE BOOL)`\n\n| Cmake option/C++ define Name            | Description                                    | Default |\n|:----------------------------------------|:-----------------------------------------------|:-------:|\n| `PCRE2CPP_ENABLE_CXX20`                 | Enables C++20 features                         |   OFF   |\n| `PCRE2CPP_DISABLE_ASSERT_ON_RELEASE`    | Disables assert on release builds              |   OFF   |\n| `PCRE2CPP_CHANGE_ASSERTS_TO_EXCEPTIONS` | Changes every assert to exceptions in pcre2cpp |   OFF   |\n| `PCRE2CPP_DISABLE_UTF8`                 | Disables UTF-8 support                         |   OFF   |\n| `PCRE2CPP_DISABLE_UTF16`                | Disables UTF-16 support                        |   OFF   |\n| `PCRE2CPP_DISABLE_UTF32`                | Disables UTF-32 support                        |   OFF   |\n\nThere is additional define if you want to use pcre2 as shared library insted of static `PCRE2CPP_SHARED_LIB`. In cmake\nproject its value depends on `BUILD_SHARED_LIBS` option\n\n### External libraries options\n\nIf you want to use external libraries not installed by project using CPM\n\n| Cmake option Name         | Description                                                      | Default |\n|:--------------------------|:-----------------------------------------------------------------|:-------:|\n| `PCRE2CPP_MSTD_EXTERNAL`  | Uses users own mstd library (tested and compatible with: 1.5.6)  |   OFF   |\n| `PCRE2CPP_PCRE2_EXTERNAL` | Uses users own pcre2 library (tested and compatible with: 10.47) |   OFF   |\n\n### Project developing options\n\nThese options are used while testing or changing code in project\n\n| Cmake option Name              | Description                                            |          Default          |\n|:-------------------------------|:-------------------------------------------------------|:-------------------------:|\n| `PCRE2CPP_BUILD_TESTS`         | Build tests                                            | `${PROJECT_IS_TOP_LEVEL}` |\n| `PCRE2CPP_BUILD_BENCHMARK`     | Build benchmark                                        | `${PROJECT_IS_TOP_LEVEL}` |\n| `PCRE2CPP_BUILD_COVERAGE`      | Enable coverage reporting                              | `${PROJECT_IS_TOP_LEVEL}` |\n| `PCRE2CPP_BUILD_DOCUMENTATION` | Build documentation                                    | `${PROJECT_IS_TOP_LEVEL}` |\n| `PCRE2CPP_BUILD_EXAMPLES`      | Build examples                                         | `${PROJECT_IS_TOP_LEVEL}` |\n| `PCRE2CPP_ENABLE_CLANG_TIDY`   | Enables clang-tidy checks                              | `${PROJECT_IS_TOP_LEVEL}` |\n| `PCRE2CPP_INSTALL`             | Enables installation of this project                   | `${PROJECT_IS_TOP_LEVEL}` |\n| `PCRE2CPP_INSTALL_TEST`        | This is only to test if installation of pcre2cpp works |            OFF            |\n\n## Benchmarks\n\n### Compilation (10,000 iterations)\n\n| No.     | std::regex (ms) | PCRE2 (ms)  | pcre2cpp (ms) |\n|:--------|:---------------:|:-----------:|:-------------:|\n| **1.**  |     72,9598     | **16,1092** |    18,5241    |\n| **2.**  |     57,5480     | **15,6274** |    18,1612    |\n| **3.**  |     57,0869     | **15,7417** |    18,3947    |\n| **4.**  |     57,3934     | **15,6203** |    18,6631    |\n| **5.**  |     44,9840     | **15,2435** |    18,5194    |\n| **6.**  |     57,6100     | **15,5350** |    18,3712    |\n| **7.**  |     43,8009     | **15,6640** |    17,8529    |\n| **8.**  |     57,7913     | **15,6265** |    18,1389    |\n| **9.**  |     59,1878     | **15,5679** |    18,3997    |\n| **10.** |     57,9911     | **15,4088** |    18,0916    |\n\n| regex          |  Avg (ms)   |            Overhead (ms)             | Per Iteration Avg (ms) |     Per Iteration Overhead (ms)     |\n|:---------------|:-----------:|:------------------------------------:|:----------------------:|:-----------------------------------:|\n| **std::regex** |   56,6353   | $${\\color{green}{\\text{-38,3236}}}$$ |         0,0057         | $${\\color{green}{\\text{-0,0038}}}$$ |\n| **PCRE2**      | **15,6144** |   $${\\color{red}{\\text{2,6973}}}$$   |       **0,0016**       |  $${\\color{red}{\\text{0,0003}}}$$   |\n| **pcre2cpp**   |   18,3117   |                  -                   |         0,0018         |                  -                  |\n\n### Match (10,000 iterations)\n\n| No.     | std::regex (ms) | PCRE2 (ms) | pcre2cpp (ms) |\n|:--------|:---------------:|:----------:|:-------------:|\n| **1.**  |    200,0510     | **7,6231** |    7,6295     |\n| **2.**  |    210,2780     | **7,7943** |    8,0054     |\n| **3.**  |    197,5870     |   7,9984   |  **7,7851**   |\n| **4.**  |    198,2510     | **7,6498** |    8,0657     |\n| **5.**  |    199,3080     |   8,0307   |  **7,7707**   |\n| **6.**  |    199,4860     |   7,9415   |  **7,8639**   |\n| **7.**  |    197,2080     |   8,0802   |  **7,9928**   |\n| **8.**  |    197,3450     | **7,7989** |    8,1371     |\n| **9.**  |    200,0030     | **7,9187** |    8,2530     |\n| **10.** |    197,8760     | **7,9905** |    8,2095     |\n\n| regex          |  Avg (ms)  |             Overhead (ms)             | Per Iteration Avg (ms) |     Per Iteration Overhead (ms)     |\n|:---------------|:----------:|:-------------------------------------:|:----------------------:|:-----------------------------------:|\n| **std::regex** |  199,7393  | $${\\color{green}{\\text{-191,7680}}}$$ |         0,0200         | $${\\color{green}{\\text{-0,0192}}}$$ |\n| **PCRE2**      | **7,8826** |   $${\\color{red}{\\text{0,0887}}}$$    |       **0,0008**       | $${\\color{green}{\\text{0,0000}}}$$  |\n| **pcre2cpp**   |   7,9713   |                   -                   |       **0,0008**       |                  -                  |\n\n### Match with all results (10,000 iterations)\n\n| No.     | std::regex (ms) | PCRE2 (ms)  | pcre2cpp (ms) |\n|:--------|:---------------:|:-----------:|:-------------:|\n| **1.**  |    200,0060     | **9,7453**  |    11,9927    |\n| **2.**  |    196,6940     | **10,7646** |    12,5312    |\n| **3.**  |    197,8630     | **9,8459**  |    16,1080    |\n| **4.**  |    198,6790     | **9,5077**  |    12,0731    |\n| **5.**  |    198,5960     | **10,1264** |    12,7155    |\n| **6.**  |    197,2710     | **9,6796**  |    12,5729    |\n| **7.**  |    217,3730     | **23,5250** |    26,8198    |\n| **8.**  |    197,2450     | **10,1512** |    12,6728    |\n| **9.**  |    202,4240     | **9,8813**  |    12,8561    |\n| **10.** |    198,0520     | **10,0214** |    13,3514    |\n\n| regex          |  Avg (ms)   |             Overhead (ms)             | Per Iteration Avg (ms) |     Per Iteration Overhead (ms)     |\n|:---------------|:-----------:|:-------------------------------------:|:----------------------:|:-----------------------------------:|\n| **std::regex** |  200,4203   | $${\\color{green}{\\text{-186,0510}}}$$ |         0,0200         | $${\\color{green}{\\text{-0,0186}}}$$ |\n| **PCRE2**      | **11,3248** |   $${\\color{red}{\\text{3,0445}}}$$    |       **0,0011**       |  $${\\color{red}{\\text{0,0003}}}$$   |\n| **pcre2cpp**   |   14,3694   |                   -                   |         0,0014         |                  -                  |\n\n## Installation\n\nAfter installing, you can use `find_package(pcre2cpp)`.\n\n### Components\n\nYou can also include components `find_pcakage(pcre2cpp COMPONENTS comp)`. They work the same way\nas [Compilation defines options](#compilation-defines-options), but\nthey provide separate components you need to include.\n\n| Component Name       | Option                                  | Target Name                    |\n|:---------------------|:----------------------------------------|:-------------------------------|\n| CXX20                | `PCRE2CPP_ENABLE_CXX20`                 | pcre2cpp::CXX20                |\n| NO_ASSERT_ON_RELEASE | `PCRE2CPP_DISABLE_ASSERT_ON_RELEASE`    | pcre2cpp::NO_ASSERT_ON_RELEASE |\n| EXCEPTIONS           | `PCRE2CPP_CHANGE_ASSERTS_TO_EXCEPTIONS` | pcre2cpp::EXCEPTIONS           |\n| NO_UTF8              | `PCRE2CPP_DISABLE_UTF8`                 | pcre2cpp::NO_UTF8              |\n| NO_UTF16             | `PCRE2CPP_DISABLE_UTF16`                | pcre2cpp::NO_UTF16             |\n| NO_UTF32             | `PCRE2CPP_DISABLE_UTF32`                | pcre2cpp::NO_UTF32             |\n\n## Example Usage\n\n### Basic Match\n\n```cpp\n#include \u003cpcre2cpp/pcre2cpp.hpp\u003e\n#include \u003ciostream\u003e\n\nusing namespace std;\nusing namespace pcre2cpp;\n\nint main() {\n    regex expression(\"\\\\d+\");\n    \n    if (expression.match(\"2\")) { // is true\n        cout \u003c\u003c \"Matches\" \u003c\u003c endl;\n    }\n\n    if (expression.match(\"a\")) { // is false\n        cout \u003c\u003c \"Matches\" \u003c\u003c endl;\n    }\n\n    if (expression.match(\"a2\")) { // is true\n        cout \u003c\u003c \"Matches\" \u003c\u003c endl;\n    }\n    \n    return 0;\n}\n```\n\n### Match with Result\n\n```cpp\n#include \u003cpcre2cpp/pcre2cpp.hpp\u003e\n#include \u003ciostream\u003e\n\nusing namespace std;\nusing namespace pcre2cpp;\n\nint main() {\n    regex expression(\"\\\\d+\");\n    \n    match_result result;\n    if (expression.match(\"aa2\", result, 2)) { // is true\n        cout \u003c\u003c \"Matches result: \" \u003c\u003c result.get_result_value() \u003c\u003c \" at: \" \n             \u003c\u003c to_string(result.get_result_global_offset()) \u003c\u003c endl;\n\n        // Should print \"Matches result: 2 at: 2\"\n    }\n    \n    return 0;\n}\n```\n\n### Match at Specified Offset\n\n```cpp\n#include \u003cpcre2cpp/pcre2cpp.hpp\u003e\n#include \u003ciostream\u003e\n\nusing namespace std;\nusing namespace pcre2cpp;\n\nint main() {\n    regex expression(\"\\\\d+\");\n    \n    if (expression.match_at(\"aa2\", 2)) { // is true\n        cout \u003c\u003c \"Matches result: 2 at: 2\" \u003c\u003c endl;\n    }\n\n    if (expression.match_at(\"aa2\", 1)) { // is false\n        cout \u003c\u003c \"Matches result: 2 at: 2\" \u003c\u003c endl;\n    }\n    \n    return 0;\n}\n```\n\n### Match at Specified Offset with Result\n\n```cpp\n#include \u003cpcre2cpp/pcre2cpp.hpp\u003e\n#include \u003ciostream\u003e\n\nusing namespace std;\nusing namespace pcre2cpp;\n\nint main() {\n    regex expression(\"\\\\d+\");\n    \n    match_result result;\n    if (expression.match_at(\"aa2\", result, 2)) { // is true\n        cout \u003c\u003c \"Matches result: \" \u003c\u003c result.get_result_value() \u003c\u003c \" at: \" \n             \u003c\u003c to_string(result.get_result_global_offset()) \u003c\u003c endl;\n\n        // Should print: \"Matches result: 2 at: 2\"\n    }\n    \n    return 0;\n}\n```\n\n### Match with Indexed Subexpression\n\n```cpp\n#include \u003cpcre2cpp/pcre2cpp.hpp\u003e\n#include \u003ciostream\u003e\n\nusing namespace std;\nusing namespace pcre2cpp;\n\nint main() {\n    regex expression(\"(\\\\d+)(a)\");\n    \n    match_result result;\n    if (expression.match(\"ab23a\", result, 1)) { // is true\n        cout \u003c\u003c \"Sub Match 0 result: \" \u003c\u003c result.get_sub_result_value(0) \u003c\u003c \" at: \"\n        \u003c\u003c result.get_sub_result_global_offset(0) \u003c\u003c \", Sub Match 1 result: \"\n        \u003c\u003c result.get_sub_result_value(1) \u003c\u003c \" at: \" \n        \u003c\u003c result.get_sub_result_global_offset(1) \u003c\u003c endl;\n\n        // Should print: \"Sub Match 0 result: 23 at: 2, Sub Match 1 result: a at: 4\"\n    }\n    \n    return 0;\n}\n```\n\n### Match with Named Subexpression\n\n```cpp\n#include \u003cpcre2cpp/pcre2cpp.hpp\u003e\n#include \u003ciostream\u003e\n\nusing namespace std;\nusing namespace pcre2cpp;\n\nint main() {\n    regex expression(\"(?\u003cnumber\u003e\\\\d+)(?\u003ca\u003ea)\");\n    \n    match_result result;\n    if (expression.match(\"ab23a\", result, 1)) { // is true\n        cout \u003c\u003c \"Sub Match \u003cnumber\u003e result: \" \u003c\u003c result.get_sub_result_value(\"number\")\n        \u003c\u003c \" at: \" \u003c\u003c result.get_sub_result_global_offset(\"number\") \n        \u003c\u003c \", Sub Match \u003ca\u003e result: \" \u003c\u003c result.get_sub_result_value(\"a\") \n        \u003c\u003c \" at: \" \u003c\u003c result.get_sub_result_global_offset(\"a\") \u003c\u003c endl;\n\n        // Should print: \"Sub Match \u003cnumber\u003e result: 23 at: 2, Sub Match \u003ca\u003e result: a at: 4\"\n    }\n    \n    return 0;\n}\n```\n\n### Match All\n\n```cpp\n#include \u003cpcre2cpp/pcre2cpp.hpp\u003e\n#include \u003ciostream\u003e\n\nusing namespace std;\nusing namespace pcre2cpp;\n\nint main() {\n    regex expression(\"\\\\d+\");\n    \n    std::vector\u003cmatch_result\u003e results;\n    if (expression.match_all(\"Ala ma 23 lata i 3 koty\", results)) { // is true\n        cout \u003c\u003c \"Match 0 result: \" \u003c\u003c results[0].get_result_value() \n        \u003c\u003c \" at: \" \u003c\u003c results[0].get_result_global_offset() \n        \u003c\u003c \", Match 1 result: \" \u003c\u003c results[1].get_result_value() \n        \u003c\u003c \" at: \" \u003c\u003c results[1].get_result_global_offset() \u003c\u003c endl;\n\n        // Should print: \"Match 0 result: 23 at: 7, Match 1 result: 3 at: 17\"\n    }\n    \n    return 0;\n}\n```\n\n## Offsets Graph\n\n![offsets graph](PCRE2CPPResult.png \"Offsets Graph\")\n\n## License\n\nThis project is licensed under the **BSD 3-Clause License with Attribution Requirement**. For more details, check\nthe [LICENSE](./LICENSE \"License\") file.\n\n## Acknowledgments\n\nThis project includes code from the [PCRE2 library](https://github.com/PhilipHazel/pcre2 \"PCRE2 github repo\"),\ndistributed under the BSD\nLicense.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaipa01%2Fpcre2cpp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmaipa01%2Fpcre2cpp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaipa01%2Fpcre2cpp/lists"}