File tree Expand file tree Collapse file tree 2 files changed +18
-0
lines changed
Expand file tree Collapse file tree 2 files changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -124,6 +124,22 @@ std::optional<date> extract_date(std::string_view s) noexcept {
124124```
125125[link to compiler explorer](https://gcc.godbolt.org/z/x64CVp)
126126
127+ ##### Using captures
128+ ```c++
129+ auto result = ctre::match<"(?<year>\\d{4})/(?<month>\\d{1,2})/(?<day>\\d{1,2})">(s);
130+ return date{result.get<"year">(), result.get<"month">, result.get<"day">};
131+
132+ // or in C++ emulation, but the object must have a linkage
133+ static constexpr ctll::fixed_string year = "year";
134+ static constexpr ctll::fixed_string month = "month";
135+ static constexpr ctll::fixed_string day = "day";
136+ return date{result.get<year>(), result.get<month>, result.get<day>};
137+
138+ // or use numbered access
139+ // capture 0 is the whole match
140+ return date{result.get<1>(), result.get<2>, result.get<3>};
141+ ```
142+
127143#### Lexer
128144``` c++
129145enum class type {
Original file line number Diff line number Diff line change @@ -25,8 +25,10 @@ int main() {
2525
2626 #if __cpp_nontype_template_parameter_class
2727 std::cout << std::string_view (match.get <" first" >()) << " \n " ;
28+ std::cout << std::string_view (match.get <1 >()) << " \n " ;
2829 #else
2930 std::cout << std::string_view (match.get <name>()) << " \n " ;
31+ std::cout << std::string_view (match.get <1 >()) << " \n " ;
3032 #endif
3133 }
3234}
You can’t perform that action at this time.
0 commit comments