Aus dem folgenden Code, ich erwarte, dass diese Ausgabe von dem entsprechenden Eingang zu bekommen:Case Sensitive teilweise Übereinstimmung mit Boost-regex
Input: FOO Output: Match
Input: FOOBAR Output: Match
Input: BAR Output: No Match
Input: fOOBar Output: No Match
Aber warum gibt es „No Match“ für die Eingabe FOOBAR?
#include <iostream>
#include <vector>
#include <fstream>
#include <sstream>
#include <boost/regex.hpp>
using namespace std;
using namespace boost;
int main (int arg_count, char *arg_vec[]) {
if (arg_count !=2) {
cerr << "expected one argument" << endl;
return EXIT_FAILURE;
}
string InputString = arg_vec[1];
string toMatch = "FOO";
const regex e(toMatch);
if (regex_match(InputString, e,match_partial)) {
cout << "Match" << endl;
} else {
cout << "No Match" << endl;
}
return 0;
}
Update:
Schließlich arbeitet sie mit folgendem Ansatz:
#include <iostream>
#include <vector>
#include <fstream>
#include <sstream>
#include <boost/regex.hpp>
using namespace std;
using namespace boost;
bool testSearchBool(const boost::regex &ex, const string st) {
cout << "Searching " << st << endl;
string::const_iterator start, end;
start = st.begin();
end = st.end();
boost::match_results<std::string::const_iterator> what;
boost::match_flag_type flags = boost::match_default;
return boost::regex_search(start, end, what, ex, flags);
}
int main (int arg_count, char *arg_vec[]) {
if (arg_count !=2) {
cerr << "expected one argument" << endl;
return EXIT_FAILURE;
}
string InputString = arg_vec[1];
string toMatch = "FOO*";
static const regex e(toMatch);
if (testSearchBool(e,InputString)) {
cout << "MATCH" << endl;
}
else {
cout << "NOMATCH" << endl;
}
return 0;
}
@Gayan: Ich habe versucht, String toMatch = "FOO *"; Es passt immer noch nicht. – neversaint
Es war nur eine Ahnung. Ich habe nicht den Luxus, mit Boost eine Test-App zu schreiben. Sorry – Gayan
Dies ist keine Shell-Erweiterung. "FOO *" wäre ein "F", gefolgt von einem "O", gefolgt von null oder mehr "O". – Svante