標準正規表現に問題があります。疑問符数量子を機能させることができません。regex_match への呼び出しは常に 0 を返します。
また、期待どおりに動作しない {0,1} も試しました。+ 量指定子のように動作します。
これが私のコードです:
#include <iostream>
#include <regex>
using namespace std;
int main(int argc, char **argv){
regex e1("ab?c");
cout << regex_match("ac", e1) << endl; // expected : 1, output 0
cout << regex_match("abc", e1) << endl; // expected : 1, output 0
cout << regex_match("abbc", e1) << endl; // expected : 0, output 0
regex e2("ab{0,1}c");
cout << regex_match("ac", e2) << endl; // expected : 1, output 0
cout << regex_match("abc", e2) << endl; // expected : 1, output 1
cout << regex_match("abbc", e2) << endl; // expected : 0, output 1
return 0;
}
次のコマンドを使用してコンパイルしました。
g++ -std=c++11 main.cpp -o regex_test
私はここで何か間違っていますか?または、なぜ機能しないのですか?