If you are interested in a single scan of input string, then try one of approaches:
using namespace std;
wregex regex( L"(a)|(b)|$" );
wcregex_iterator results_begin( str.c_str( ), str.c_str( ) + str.length( ), regex );
wcregex_iterator results_end{};
wstring data;
for( auto i = results_begin; i != results_end; ++i )
{
const wcmatch& match = *i;
data += match.prefix( ).str() + ( match[1].matched ? L"+" : match[2].matched ? L"*" : L"" );
}
or
for( auto i = results_begin; i != results_end; ++i )
{
const wcmatch& match = *i;
if( match[1].matched ) data += match.format( L"$`+" );
else if( match[2].matched ) data += match.format( L"$`*" );
}
It is also possible to use for_each or transform.