From f7c041f5605bcfa09ed040f897b2615da6209594 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Fri, 6 May 2022 15:06:56 +0100 Subject: Implement support for regex capture groups. --- src/modules/m_regex_stdlib.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/modules/m_regex_stdlib.cpp') diff --git a/src/modules/m_regex_stdlib.cpp b/src/modules/m_regex_stdlib.cpp index 0f2d31a61..191625221 100644 --- a/src/modules/m_regex_stdlib.cpp +++ b/src/modules/m_regex_stdlib.cpp @@ -54,6 +54,22 @@ public: { return std::regex_search(text, regex); } + + std::optional Matches(const std::string& text) override + { + std::smatch matches; + if (!std::regex_search(text, matches, regex)) + return std::nullopt; + + Regex::Captures captures(matches.size()); + for (const auto& match : matches) + captures.push_back(match); + + // The stdregex engine does not support named captures. + static const Regex::NamedCaptures unusednc; + + return Regex::MatchCollection(std::move(captures), unusednc); + } }; class StdLibEngine final -- cgit v1.3.1-10-gc9f91