API Reference
This chapter contains the complete reference documentation for the public API of the Erbsland Regular Expression library.
While the Get Started section focuses on learning the basics and building your first examples, the reference chapters are designed to answer detailed questions about specific types, methods, and behaviour. You typically come here once you already know what you want to do and need to look up how a particular part of the API works.
The following example demonstrates a common real-world workflow using the library:
compile regular expressions,
match them against input data, and
process the resulting matches.
1#include <erbsland/all_re.hpp>
2
3// ... std includes ...
4
5using namespace el::re;
6
7// ... type definitions and helper functions ...
8
9int main(int argc, char **argv) {
10 try {
11 if (argc < 2) {
12 throw std::runtime_error(std::format("Usage: {} <html-file>\n", argv[0]));
13 }
14
15 const auto reTag = RegEx::compile(R"((?is)<([a-z]+)([^>]*)>)");
16 const auto reAttribute = RegEx::compile(R"((?is)\s+([a-z]+)=("[^"]*"|\S+)?)");
17
18 auto html = readFileToString(argv[1]);
19 auto tagCounts = CountMap{};
20 auto attributeCounts = CountMap{};
21
22 std::cout << "Scanning file\n";
23
24 for (const auto &match : reTag->findAllView(html)) {
25 tagCounts[std::string(match->content(1))] += 1;
26
27 for (const auto &attributeMatch : reAttribute->findAllView(match->content(2))) {
28 attributeCounts[std::string(attributeMatch->content(1))] += 1;
29 }
30 }
31
32 const auto tagRows = sortedRowsFromCounts(tagCounts);
33 const auto attributeRows = sortedRowsFromCounts(attributeCounts);
34
35 printStats(tagRows, "Tag Statistics:");
36 printStats(attributeRows, "Attribute Statistics:");
37
38 return 0;
39 } catch (const std::runtime_error &error) {
40 std::cout << error.what() << '\n';
41 return 1;
42 }
43}
This example highlights a typical usage pattern of the API: compile → match → process match results.
For clarity, helper functions and type declarations are omitted here. You can find the complete example, including all supporting code, in Write the Main Functionality.
The following reference pages document all public interfaces in detail.