#include <regex>
#include <iostream>

using namespace std;

int main() {
    try {
        regex R(R"(^([^;]+);(?:\s*([^=]+)=((\"?)([^\"]*)\4);?)*$)");
        string s("attached; filename=\"Hello, world!.docx\"");
        smatch m;
		if (regex_search(s, m, R)) {
			std::cout << m[0] << std::endl;
		}
    }
    catch (const regex_error& e) {
        cout << "regex_error caught: " << e.what() << '\n';
        if (e.code() == regex_constants::error_brack) {
            cout << "The code was error_brack\n";
        }
    }
    return 0;
}