Cppregex is a very simple, single header file, easy to use C++11 std::regex wrapper for lazy people who just want to use regex in C++ without having to mingle with std::regex boilerplate code. In other words, a simple C++ regex library.
Of course, this requires C++11 to work.
Include cppregex.h in your project and you are good to go.
This is #include "cppregex.h" for those of us that like to copy & paste.
Examples for every function in the library are written in unit\unit.cpp.
Cppregex includes the following functions:
-
bool regex::match(string text, string regex)
returnstrueiftextmatches theregex,falseotherwise. -
bool regex::contains(string text, string regex)
returnstrueiftextcontains a substring that matchesregex,falseotherwise. -
int regex::index(string text, string regex)
returns the position of the first substring oftextthat matchesregex,-1if none was found. -
vector<int> regex::indices(string text, string regex)
returns a vector if ints containing all the positions of the substrings oftextthat matchregex. An emptyvector<int>is returned if none was found. -
pair<int, unsigned int> regex::indexLength(string text, string regex)
returns the position and length of the first substring oftextthat matchesregex.<-1, 0>is returned if none was found. -
vector<pair<int, unsigned int>> regex::indicesLengths(string text, string regex)
returns a vector of pairs of position and length of each substring oftextthat matchesregex. An emptyvector<pair<int, unsigned int>>is returned if none was found. -
string regex::search(string text, string regex)
returns the first substring oftextthat matchesregex,""if none was found. -
vector<string> regex::searchAll(string text, string regex)
returns all the substrings oftextthat matchregex, an emptyvector<string>is returned if none was found. -
string regex::before(string text, string regex)
returns all the text found intextbefore a substring that matchedregexwas found. -
string regex::after(string text, string regex)
returns all the text found intextafter a substring that matchedregexwas found. -
string regex::replace(string text, string regex, string newValue)
returns a copy oftextwith the first substring that matchedregexreplaced bynewValue. -
string regex::replaceAll(string text, string regex, string newValue)
returns a copy oftextwith the every substring that matchedregexreplaced bynewValue.
Cppregex is released under the MIT License so you are free to do whatever you want with it. Enjoy!
