#include <iostream>
#include <regex>
#include <string>
using namespace std;

int main() {
	string foo("lorem ipsum");
	match_results<string::reverse_iterator> sm;
	
	if(regex_match(foo.rbegin(), foo.rend(), sm, regex("(\\w+)\\s+(\\w+)"))){
		cout << sm[1] << ' ' << sm[2] << endl;
	}else{
		cout << "bad\n";
	}
	
	return 0;
}