我想匹配升壓一個簡單的表達,但它的行爲奇怪...下面的代碼應匹配,並顯示「A」從第一和第二串:boost xpressive:錯誤的匹配?
#include <iostream>
#include <boost/xpressive/xpressive.hpp>
#include "stdio.h"
using namespace boost::xpressive;
void xmatch_action(const char *line) {
cregex g_re_var;
cmatch what;
g_re_var = cregex::compile("\\s*var\\s+([\\w]+)\\s*=.*?");
if (regex_match(line, what, g_re_var)) {
printf("OK\n");
printf(">%s<\n", what[1]);
}
else {
printf("NOK\n");
}
}
int main()
{
xmatch_action("var a = qqq");
xmatch_action(" var a = aaa");
xmatch_action(" var abc ");
}
,但我實際的輸出是:
OK
>a = qqq<
OK
>a = aaa<
NOK
,它應該是
OK
>a<
OK
>a<
NOK
小測試結果;那些都OK:'cout <<什麼[1] << endl; printf(「%s \ n」,what [1] .str()。c_str()); printf(「%s \ n」,string(what [1])。c_str());'This is not:'printf(「%s \ n」,what [1]);'' –