|
1 | 1 | # pcre2cpp
|
2 |
| - |
3 |
| -# pcre2cpp - Wrapper for PCRE2 library |
4 | 2 |
|
5 |
| -This project is licensed under the BSD 3-Clause License with Attribution Requirement, and it uses the PCRE2 library which is also licensed under the BSD License. |
| 3 | +**pcre2cpp** is a C++ wrapper for the PCRE2 (Perl Compatible Regular Expressions) library written in C. It provides an object-oriented interface for the original PCRE2 library, while maintaining the same functionality and behavior. |
6 | 4 |
|
7 |
| -## PCRE2 License Information |
| 5 | +## Features |
8 | 6 |
|
9 |
| -The PCRE2 library is distributed under the BSD License, with the following conditions: |
10 |
| -- Redistributions of source code must retain the copyright notice, list of conditions, and disclaimer. |
11 |
| -- Redistributions in binary form must reproduce the copyright notice, list of conditions, and disclaimer in documentation or other materials. |
12 |
| -- The name of the University of Cambridge and contributors cannot be used to endorse or promote products derived from this software without permission. |
| 7 | +- Object-oriented interface to PCRE2. |
| 8 | +- Compatible with C++20. |
| 9 | +- Easy to use regular expression matching with built-in result capturing. |
13 | 10 |
|
14 |
| -PCRE2 is written by Philip Hazel (University of Cambridge) and Zoltan Herczeg. |
| 11 | +## Installation |
| 12 | + |
| 13 | +To use **pcre2cpp**, you need to link it statically with your project. Simply download the latest release and follow these steps: |
| 14 | + |
| 15 | +1. Download the latest release of **pcre2cpp**. |
| 16 | +2. Ensure that you have the PCRE2 library linked in your project (you will need it as a dependency). |
| 17 | +3. Link the `pcre2cpp` library statically in your build system (e.g., `CMake` or `Make`). |
| 18 | + |
| 19 | +Example for linking in `CMake`: |
| 20 | +```cmake |
| 21 | +find_package(pcre2cpp REQUIRED) |
| 22 | +target_link_libraries(your_project_name PRIVATE pcre2cpp) |
| 23 | +``` |
| 24 | + |
| 25 | +## Example Usage |
| 26 | + |
| 27 | +### Basic Match |
| 28 | + |
| 29 | +```cpp |
| 30 | +#include <pcre2cpp/pcre2cpp.hpp> |
| 31 | +#include <iostream> |
| 32 | + |
| 33 | +using namespace std; |
| 34 | +using namespace pcre2cpp; |
| 35 | + |
| 36 | +int main() { |
| 37 | + regex expression("\\d+"); |
| 38 | + |
| 39 | + if (expression.match("2")) { |
| 40 | + cout << "Matches" << endl; |
| 41 | + } |
| 42 | + |
| 43 | + return 0; |
| 44 | +} |
| 45 | +``` |
| 46 | + |
| 47 | +### Match with Result |
| 48 | + |
| 49 | +```cpp |
| 50 | +#include <pcre2cpp/pcre2cpp.hpp> |
| 51 | +#include <iostream> |
| 52 | + |
| 53 | +using namespace std; |
| 54 | +using namespace pcre2cpp; |
| 55 | + |
| 56 | +int main() { |
| 57 | + regex expression("\\d+"); |
| 58 | + |
| 59 | + match_result result; |
| 60 | + if (expression.match("aa2", result, 2)) { |
| 61 | + cout << "Matches result: " << result.getValue() << " at: " |
| 62 | + << to_string(result.getOffset() + 2) << endl; |
| 63 | + } |
| 64 | + |
| 65 | + return 0; |
| 66 | +} |
| 67 | +``` |
| 68 | + |
| 69 | +### Match at Specific Offset |
| 70 | + |
| 71 | +```cpp |
| 72 | +#include <pcre2cpp/pcre2cpp.hpp> |
| 73 | +#include <iostream> |
| 74 | + |
| 75 | +using namespace std; |
| 76 | +using namespace pcre2cpp; |
| 77 | + |
| 78 | +int main() { |
| 79 | + regex expression("\\d+"); |
| 80 | + |
| 81 | + if (expression.match_at("aa2", 2)) { |
| 82 | + cout << "Matches at: 2" << endl; |
| 83 | + } |
| 84 | + |
| 85 | + return 0; |
| 86 | +} |
| 87 | +``` |
| 88 | + |
| 89 | +## Requirements |
| 90 | + |
| 91 | +- C++20 or newer. |
| 92 | +- PCRE2 library (https://github.com/PhilipHazel/pcre2). |
| 93 | + |
| 94 | +## License |
| 95 | + |
| 96 | +This project is licensed under the **BSD 3-Clause License with Attribution Requirement**. For more details, check the [LICENSE](./LICENSE) file. |
| 97 | + |
| 98 | +## Acknowledgments |
| 99 | + |
| 100 | +This project includes code from the [PCRE2 library](https://github.com/PhilipHazel/pcre2), distributed under the BSD License. |
0 commit comments