simple regex implementation in C++