#include <iostream>
#include <regex>
#include <sstream>
#include <vector>
std::vector<std::string> split(const std::string &str) {
std::regex rgx(""); //what goes here??
std::smatch base_match;
std::regex_search(str, base_match, rgx);
return {base_match.begin(), base_match.end()};
}
std::ostream &operator<<(std::ostream &os,
const std::vector<std::string> &strs) {
for (const auto &str : strs) {
os << "-> " << str << "\n";
}
return os;
}
int main(int argv, char **argc) {
std::cout << split("asdasd,dasdasd,adadada");
return 0;
}
我希望有一个正则表达式解决方案(不使用sregex_token_iterator或boost),它为逗号分隔列表提供子匹配并跳过逗号(以及逗号之后/之前的空格)。
expected output:
asdasd
dasdasd
adadada
答案 0 :(得分:1)