C++ 使用命名捕获查找给定正则表达式中命名组的所有名称
我想知道给定正则表达式中是否有一个命名捕获组,因此我将使用命名捕获来查找该表达式中的所有名称 请参阅下面的代码片段:C++ 使用命名捕获查找给定正则表达式中命名组的所有名称,c++,regex,boost,C++,Regex,Boost,我想知道给定正则表达式中是否有一个命名捕获组,因此我将使用命名捕获来查找该表达式中的所有名称 请参阅下面的代码片段: std::string expr = "(?<ns>\\S+)"; // (?<ns>\S+) boost::regex re("\\(\\?\\<(?<name>.+)\\>"); // \(\?\<(?<name>.+)\> bool found = boost::
std::string expr = "(?<ns>\\S+)"; // (?<ns>\S+)
boost::regex re("\\(\\?\\<(?<name>.+)\\>"); // \(\?\<(?<name>.+)\>
bool found = boost::regex_search(expr, re); // **found is always false**
std::string expr=“(?\\S+)”//(?\S+)
boost::regex re(“\\(\\?\\”);/\(\\
bool found=boost::regex_search(expr,re);//**found始终为false**
我还尝试使用以下两个在线regex测试人员来验证,他们都工作并找到了“ns”
< >我使用的C++ Boost库的版本为1.59 不应逃避<代码> <代码和代码> <代码>。试试这个:
"\\(\\?<(?<name>.+)>"
“\\(\\?”
Update:最后,我使用这个表达式“\(\?”来查找命名的组名。