Answer the question
In order to leave comments, you need to log in
Why don't regex work?
Is there a simple code why std::regex_search returns true, but the matches themselves are not displayed?
#include <iostream>
#include <regex>
int main(int argc, const char * argv[])
{
std::string strs[] = {
"/users/{id}",
"/users/{i:id}"
};
std::regex pattern("{(?:(\\w+):)*(\\w+)}");
std::smatch matches;
for (auto str : strs) {
std::cout << "String: " << str << std::endl;
std::cout << "Match: " << std::boolalpha << std::regex_search(str, matches, pattern) << std::endl;
for (auto match : matches) {
std::cout << match.str() << std::endl;
}
}
}
String: /users/{id}
Match: true
String: /users/{i:id}
Match: true
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question