#include <iostream>
#include <string>
#include <vector>
#include <regex>
std::vector<std::string> split_keep_delims(
const std::string& s,
const std::string& delimiters)
{
// Build a character class: e.g. ",;|" → "([,;|])"
std::string pattern = "(" + delimiters + ")";
std::regex re(pattern);
std::sregex_token_iterator it(s.begin(), s.end(), re, {-1, 0});
std::sregex_token_iterator end;
std::vector<std::string> result;
for (; it != end; ++it) {
if (!it->str().empty())
result.push_back(it->str());
}
return result;
}
int main() {
auto parts = split_keep_delims("aa,bbb;cccc|ddddd", "[,;|]");
for (auto& p : parts)
std::cout << "[" << p << "] ";
}
/*
run:
[aa] [,] [bbb] [;] [cccc] [|] [ddddd]
*/